[Async-sig] await question

Nathaniel Smith njs at pobox.com
Mon Dec 10 13:45:18 EST 2018


Yeah, 'await' makes it *possible* for the function you're calling to return
control to the event loop, but returning is still an explicit action that
the function has to take.

In asyncio, the only operation that actually returns control to the event
loop is awaiting a Future object.

In Trio, we make a documented guarantee that all the async functions in the
'trio' namespace do in fact return control to the event loop (we call this
a "checkpoint").

In both cases, the effect is the same: if a function never actually awaits
a Future/calls one of Trio's built-in async functions, either directly or
indirectly, then it won't return to the event loop.

(And curio actually has a number of primitives that you call with await,
and that do in fact return to the event loop, but that still don't actually
let other tasks run, which I found pretty confusing. This is one of the
major reasons I stopped using curio.)

-n

On Mon, Dec 10, 2018, 04:32 Dima Tisnek <dimaqq at gmail.com wrote:

> No, in this case fib(1) is resolved instantly, thus it's caller is
> resolved instantly, thus...
>
> On Mon, 10 Dec 2018 at 9:28 PM, Pradip Caulagi <caulagi at gmail.com> wrote:
>
>> I was wondering if every use of 'await' should return the control to
>> event loop? So in this example -
>> https://gist.github.com/caulagi/3edea8cf734495f2592528a48f99e1d2 - I
>> was hoping I would see 'A', 'B' to be mixed, but I see only 'A'
>> followed by 'B'. What am I missing? I am using Python 3.7.1.
>>
>> How is my example different from
>> https://docs.python.org/3.7/library/asyncio-task.html#asyncio.run?
>>
>> Thanks.
>> _______________________________________________
>> Async-sig mailing list
>> Async-sig at python.org
>> https://mail.python.org/mailman/listinfo/async-sig
>> Code of Conduct: https://www.python.org/psf/codeofconduct/
>>
> _______________________________________________
> Async-sig mailing list
> Async-sig at python.org
> https://mail.python.org/mailman/listinfo/async-sig
> Code of Conduct: https://www.python.org/psf/codeofconduct/
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/async-sig/attachments/20181210/9326e179/attachment.html>


More information about the Async-sig mailing list