asyncio - run coroutine in the background

Frank Millman frank at chagford.com
Tue Feb 16 08:52:01 EST 2016


"Kevin Conway"  wrote in message 
news:CAKF=+dim8wzPRvm86_V2W5-XSopCcHvgm0Hy8r4xeHDYzy_P4w at mail.gmail.com...
>
> If you're handling coroutines there is an asyncio facility for "background
> tasks". The ensure_future [1] will take a coroutine, attach it to a Task,
> and return a future to you that resolves when the coroutine is complete.
> The coroutine you schedule with that function will not cause your current
> coroutine to wait unless you await the future it returns.
>
> [1]
> https://docs.python.org/3/library/asyncio-task.html#asyncio.ensure_future
>

Thank you Kevin!

That works perfectly, and is much neater than my effort.

Frank




More information about the Python-list mailing list