There is an application that handles tweets received via streaming api. Tweet processing takes place in a separate function of the form

async def process_tweet(text): ... async for tweet in stream: await process_tweet(tweet['text']) 

But - accordingly, the application is ready to process the new tweet only after the completion of the processing of the past. In this case, parallel processing of several tweets should not be a problem - respectively, I would like to implement it. That is something like

 async def process_tweet(text): ... async for tweet in stream: run_without_waiting(process_tweet(tweet['text'])) 

    1 answer 1

    Through ensure_future usually. But there is a nuance. It will not be executed immediately, but will be put on the stack and executed before the next asynchronous function is called. This is suitable for short functions. To make it run in the background it is better to look at run_in_executor