This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

Author hniksic
Recipients asvetlov, docs@python, hniksic, xtreak, yselivanov
Date 2018-09-30.06:58:10
SpamBayes Score -1.0
Marked as misclassified Yes
Message-id <1538290690.92.0.545547206417.issue34476@psf.upfronthosting.co.za>
In-reply-to
Content
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.
History
Date User Action Args
2018-09-30 06:58:10hniksicsetrecipients: + hniksic, asvetlov, docs@python, yselivanov, xtreak
2018-09-30 06:58:10hniksicsetmessageid: <1538290690.92.0.545547206417.issue34476@psf.upfronthosting.co.za>
2018-09-30 06:58:10hniksiclinkissue34476 messages
2018-09-30 06:58:10hniksiccreate