[issue40800] asyncio.sleep(0) should "yield" back to the event loop, but it doesn't behave as expected
Bar Harel
report at bugs.python.org
Tue Dec 1 12:47:12 EST 2020
Bar Harel <bzvi7919 at gmail.com> added the comment:
It relinquishes control for exactly one event loop cycle.
You'll see that it takes two or three cycles and then gets cancelled correctly.
The reason being is that recovery from your `await asyncio.sleep(1)` takes two or three cycles. (Under the hood, a few `asyncio.call_soon()` are called in a chain and only 1 is executed each cycle).
This is not a bug, but rather intended behavior. You should probably use `asyncio.to_thread()` or preferably run cpu-intensive code on a different process.
@triage Please close as not-a-bug.
----------
nosy: +bar.harel
_______________________________________
Python tracker <report at bugs.python.org>
<https://bugs.python.org/issue40800>
_______________________________________
More information about the Python-bugs-list
mailing list