asyncio - run coroutine in the background
frank at chagford.com
Mon Feb 15 02:16:34 EST 2016
"Marko Rauhamaa" wrote in message news:8737sumpjl.fsf at elektro.pacujo.net...
> "Frank Millman" <frank at chagford.com>:
> > Using asyncio, there are times when I want to execute a coroutine which
> > is time-consuming. I do not need the result immediately, and I do not
> > want to block the current task, so I want to run it in the background.
> You can't run code "in the background" using asyncio. Coroutines perform
> cooperative multitasking in a single thread on a single CPU.
> Parallel processing requires the use of threads or, often preferably,
> To put it in another way, never run time-consuming code in asyncio.
No arguments there.
I started with a task that ran quickly, but as I added stuff it started to
The execution of the task involves calling some existing functions, which
are themselves coroutines. As you have noted elsewhere, once you turn one
function into a coroutine, all calls higher up the chain have to be
coroutines as well.
The benefit of my class is that it enables me to take the coroutine and run
it in another thread, without having to re-engineer the whole thing.
Hope this makes sense.
More information about the Python-list