Fire and forget http requests #9464
-
I am trying to send a large number (hundreds or thousands) of HTTP POST requests in a fire-and-forget manner, meaning I don't want to wait for the responses of these requests. I am creating a session with aiohttp.ClientSession() and sending the requests using asyncio.create_task(session.myfunc(url)). However, I believe that the session object cannot be closed until all the requests have completed, which means the calling function needs to wait before exiting and closing the session. This seems to defeat the purpose of fire-and-forget. What am I missing? Thanks in advance for any help |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 4 replies
-
create_task() cannot be used for fire-and-forget (pretty sure it highlights this in the docs these days). Instead, use aiojobs or something similar. You can then await the scheduler's wait_and_close() before exiting the ClientSession. |
Beta Was this translation helpful? Give feedback.
https://aiojobs.readthedocs.io/en/stable/#usage-example