bpo-34701: Updated the asyncio documentation to clearly state what happens if an asyncio coroutine recursively calls itself. by zorn96 · Pull Request #9339 · python/cpython (original) (raw)
…ppens if an asyncio coroutine recursively calls itself.
Currently, all documentation sort of dances around what happens in this case. The documentation outlines what occurs if a coroutine calls "await coroutine" or "yield from coroutine" on another coroutine, but makes no mention of what occurs if a coroutine does that recursively.
If a coroutine recursively calls itself, then the call to itself will be executed immediately, without allowing anything else to be scheduled. This is significantly different from when a coroutine calls another coroutine. When a coroutine calls another coroutine, the called coroutine is scheduled to be executed later, and other things are allowed to happen before it. So these are completely different behaviors.
The behavior when a coroutine does that recursively is not intuitive, and can be breaking for any systems that rely on asyncio for interweaving but utilize recursive processing functions. Therefore, we should be very explicit about what happens in this scenario.
Testing: A script that reliably reproduces the behavior being documented is attached to the python issue that is linked to this commit.