[Python-ideas] Learning from the shell in supporting asyncio background calls

Nathaniel Smith njs at pobox.com
Sat Jul 11 07:16:04 CEST 2015


On Jul 11, 2015 12:04 AM, "Nick Coghlan" <ncoghlan at gmail.com> wrote:
>
[...]
>
> Concatenating some of the example code from the post together gives
> this demonstration of the basic UX:
>
>     >>> async def ticker():
>     ...     for i in itertools.count():
>     ...         print(i)
>     ...         await asyncio.sleep(1)
>     ...
>     >>> ticker1 = run_in_background(ticker())
>     >>> ticker1
>     <Task pending coro=<ticker() running at <stdin>:1>>
>     >>> run_in_foreground(asyncio.sleep(5))
>     0
>     1
>     2
>     3
>     4
>
> If there isn't a coroutine currently running in the foreground, then
> background coroutines don't run either. All of the currently running
> tasks can be interrogated through the existing
> asyncio.Task.all_tasks() class method.

For what it's worth, I find it extraordinarily confusing that background
tasks don't run in the background and foreground tasks don't run in the
foreground.

The functionality doesn't strike me as obviously unreasonable, it just
doesn't at all match my expectations from encountering these words in the
shell context.

Maybe start_suspended(...) and unsuspend_all_until(task)?

-n
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/python-ideas/attachments/20150711/3a28d1ec/attachment.html>


More information about the Python-ideas mailing list