Thursday 23 February 2017

python - Simple asynchronous task with asyncio

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?

No comments:

Post a Comment

c++ - Does curly brackets matter for empty constructor?

Those brackets declare an empty, inline constructor. In that case, with them, the constructor does exist, it merely does nothing more than t...