0

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?

2
  • asyncio is for coordinating multiple cooperatively multitasking functions. The thread can only run one function at a time, but with async/await you 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. Commented Apr 11, 2018 at 8:53
  • Definitely wrong marked. OP doesn't seem to understand how asyncio works 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 using asyncio. Commented Apr 11, 2018 at 8:59

0

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.