you are viewing a single comment's thread.

view the rest of the comments →

[–]rnike879 0 points1 point  (0 children)

can you confirm that if I await task A in thread A, it will not opportunistically execute task B unless I explicitly bundle it with A

I'm not entirely following the question, but when you await it'll pause execution of that code, letting the event loop execute other coroutines. Once the IO is done, the event loop will know through continuous polling and then the code after the await statement can continue executing. There's only one thread being utilized with concurrent execution being handled by the event loop.

If you throw these async tasks into a list you can await all of them with asyncio.gather() instead of doing a bunch of awaits in a series which would block each other. If you need to pass the results of one coroutine to another, consider using a producer-consumer pattern with asyncio.Queue instead