Message326709
The issue is because the current documentation *doesn't* say that "`asyncio.sleep()` always pauses the current task and switches execution to another one", it just says that it "blocks for _delay_ seconds".
With that description a perfectly valid implementation could be further optimized with:
async def sleep(delay):
if delay <= 0:
return
...
In which case `await sleep(0)` would *not* cause a task switch. And this is not an unreasonable thing to expect because there are many other potentially-switching situations in asyncio that sometimes don't cause a switch, such as await `queue.get()` from a non-empty queue or await `await stream.readline()` from a socket stream that has a line to provide.
The user who wants to implement a "yield control to event loop" has to look at the source to find out how delay==0 is handled, and then they have to wonder if it's an implementation detail. https://github.com/python/asyncio/issues/284 states that the behavior is explicit and here to stay, but that promise has never made it into the actual documentation. |
|
Date |
User |
Action |
Args |
2018-09-30 06:58:10 | hniksic | set | recipients:
+ hniksic, asvetlov, docs@python, yselivanov, xtreak |
2018-09-30 06:58:10 | hniksic | set | messageid: <1538290690.92.0.545547206417.issue34476@psf.upfronthosting.co.za> |
2018-09-30 06:58:10 | hniksic | link | issue34476 messages |
2018-09-30 06:58:10 | hniksic | create | |
|