[Python-Dev] PEP 492 quibble and request (original) (raw)
Guido van Rossum guido at python.org
Sat May 2 23:09:51 CEST 2015
- Previous message (by thread): [Python-Dev] PEP 492 quibble and request
- Next message (by thread): [Python-Dev] PEP 492 quibble and request
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
On Sat, May 2, 2015 at 1:18 PM, Arnaud Delobelle <arnodel at gmail.com> wrote:
On 1 May 2015 at 20:59, Guido van Rossum <guido at python.org> wrote: > On Fri, May 1, 2015 at 12:49 PM, Ron Adam <ron3200 at gmail.com> wrote: >> >> >> Another useful async function might be... >> >> async def yielding(): >> pass >> >> In a routine is taking very long time, just inserting "await yielding()" >> in the long calculation would let other awaitables run. >> > That's really up to the scheduler, and a function like this should be > provided by the event loop or scheduler framework you're using.
Really? I was under the impression that 'await yielding()' as defined above would actually not suspend the coroutine at all, therefore not giving any opportunity for the scheduler to resume another coroutine, and I thought I understood the PEP well enough. Does this mean that somehow "await x" guarantees that the coroutine will suspend at least once?
You're correct. That's why I said it should be left up to the framework -- ultimately what you do have to put in such a function has to be understood by the framenwork. And that's why in other messages I've used await asyncio.sleep(0) as an example. Look up its definition.
To me the async def above was the equivalent of the following in the 'yield from' world:
def yielding(): return yield # Just to make it a generator Then "yield from yielding()" will not yield at all - which makes its name rather misleading!
-- --Guido van Rossum (python.org/~guido) -------------- next part -------------- An HTML attachment was scrubbed... URL: <http://mail.python.org/pipermail/python-dev/attachments/20150502/6032f70a/attachment.html>
- Previous message (by thread): [Python-Dev] PEP 492 quibble and request
- Next message (by thread): [Python-Dev] PEP 492 quibble and request
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]