Consider a single-threaded Python program. A coroutine named "first" is blocked on I/O. The subsequent instruction is "await second." Is the coroutine "second" guaranteed to execute immediately until it blocks on I/O? Or, can "first" resume executing (due to the I/O operation completing) before "second" is invoked?
标签:
python-asyncio
相关问题
- Python asyncio: unreferenced tasks are destroyed b
- Run two async functions without blocking each othe
- How do I download a large list of URLs in parallel
- Testing aiohttp client with unittest.mock.patch
- Python Asyncio subprocess never finishes
相关文章
- Await an async function in Python debugger
- Waiting for a task to complete after KeyboardInter
- How to obtain an event loop from Quart
- How to implement timeout in asyncio server?
- Python async io stream
- Asyncio function works when called from script but
- Detect an idle asyncio event loop
- How i can get new ip from tor every requests in th
Asyncio implemented a way that
second
would start executing until it would return control to event loop (it usually happens when it reaches some I/O operation) and only after itfirst
can be resumed. I don't think it somehow guaranteed to you, but hardly believe this implementation will be changed either.If for some reason you don't want
first
to resume executing until some part ofsecond
reached, it's probably better explicitly to use Lock to blockfirst
from executing before moment you want.Example to show when control returns to event loop and execution flow can be changed:
Output: