<div dir="ltr">Sorry I don't have time to write out a longer answer (with, you know, working code), but a of couple of rough thoughts from recent experience.<div><br></div><div> - all GUI stuff must happen on the main thread (if you do threads), but for some backends `draw_idle()` maybe thread safe.</div><div> - for asyncio no blocking part of the task should be slower than 1/10 a second (that is the time between subsequent calls to `yield from`/`yield`/`await`). Anything slower and you will need to push it out of the main thread/process. It brings a bunch of complexity, but I would look at something like dask. The futures look to have a `add_done_callback` method which you can use to bridge to an asyncio.Event that you can await on, (although you might run into some tornado vs asyncio issues). Looks like someone has already done the work of hiding multiprocess behind asyncio (<a href="https://github.com/dano/aioprocessing">https://github.com/dano/aioprocessing</a>). Would not go with threads unless you have a lot of gil releasing code.</div><div> - integrating asyncio and GUIs are about the same problem as integrating GUIs and the command line, you have two infinite loops that both want to run the show (and block while waiting for the slow human). I have been using <a href="https://github.com/NSLS-II/bluesky/blob/master/bluesky/utils.py#L684">https://github.com/NSLS-II/bluesky/blob/master/bluesky/utils.py#L684</a> to good effect at my day-job for keeping figures alive under asyncio, but we are mostly waiting for (motion control related) network / motion. You install a self-perpetuating 'call_later' on to the asyncio event loop that drains the GUI events (which lets all of their callbacks run and re-draws the figure).</div><div> - A super embarrassing (but functional) qt example is where I use qt threads + ipyparallel is <a href="https://github.com/tacaswell/leidenfrost/blob/master/leidenfrost/gui/proc_gui.py">https://github.com/tacaswell/leidenfrost/blob/master/leidenfrost/gui/proc_gui.py</a> In this case I let the GUI event loop run the show.</div><div><br></div><div>Tom</div><div><br></div><div><br></div></div><br><div class="gmail_quote"><div dir="ltr">On Thu, Feb 23, 2017 at 3:45 PM Ludwig Schwardt <<a href="mailto:ludwig.schwardt@gmail.com">ludwig.schwardt@gmail.com</a>> wrote:<br></div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div dir="ltr" class="gmail_msg">Hi Juan,<div class="gmail_msg"><br class="gmail_msg"></div><div class="gmail_msg">Funny that you should mention it... I was busy with the exact same thing today :-)</div><div class="gmail_msg"><br class="gmail_msg"></div><div class="gmail_msg">It is as you said: the matplotlib GUI has to run on the main thread. The trick seems to be to start the asyncio loop in a second background thread and communicate with the GUI running on the main thread via a queue. I found <a href="http://stackoverflow.com/a/34882411" class="gmail_msg" target="_blank">this</a> StackOverflow answer very helpful. </div><div class="gmail_msg"><br class="gmail_msg"></div><div class="gmail_msg">As an aside, I eventually ditched asyncio for an even simpler threading + queue solution (being stuck in Python 2.7...).</div><div class="gmail_msg"><br class="gmail_msg"></div><div class="gmail_msg">Cheers,</div><div class="gmail_msg"><br class="gmail_msg"></div><div class="gmail_msg">Ludwig</div><div class="gmail_msg"><br class="gmail_msg"></div><div class="gmail_msg">P.P.S. I have an old matplotlib GUI app that used to disable the button during the long-running task (run from the on_clicked callback) to indicate when the GUI becomes available again. This behaviour does not seem to work anymore on modern matplotlib, hence my need to investigate background threads :-)</div><div class="gmail_msg"><br class="gmail_msg"></div></div>
_______________________________________________<br class="gmail_msg">
Matplotlib-users mailing list<br class="gmail_msg">
<a href="mailto:Matplotlib-users@python.org" class="gmail_msg" target="_blank">Matplotlib-users@python.org</a><br class="gmail_msg">
<a href="https://mail.python.org/mailman/listinfo/matplotlib-users" rel="noreferrer" class="gmail_msg" target="_blank">https://mail.python.org/mailman/listinfo/matplotlib-users</a><br class="gmail_msg">
</blockquote></div>