
On Jul 11, 2015 12:04 AM, "Nick Coghlan" <ncoghlan@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