I have a function that takes a lot of time to run, but actually has returns no program relevant value -- it simply does some IO / plotting to store current progress.
I would like to asynchronously call it, and have found the newly core'd asyncio library. My main function then looks something like
async def doStuff(input): plt.figure() plt.plot(input) plt.savefig('foobar.pdf') However, it's unclear to me how to exactly call that. All examples I've seen do a variant on
loop = asyncio.get_event_loop() # Blocking call which returns when the hello_world() coroutine is done loop.run_until_complete(doStuff() but actually, I just need a single call (not a loop), and explicitely do not want to wait ever for it to finish. What's the most trivial implementation of that in the asyncio framework?
asynciois for coordinating multiple cooperatively multitasking functions. The thread can only run one function at a time, but withasync/awaityou can suspend one function and let another run; the event loop coordinates when to resume which function. This does not appear to be what you're after, you want to have code run on a different thread entirely in parallel with other code.asyncioworks at all. He need more information than just "wrap event loop in a background thread." First, there is no asynchronous disk IO support in Linux. Second, this task can be done by just launching a background thread without usingasyncio.