[IPython-dev] Detecting GUI mainloop running in IPython

Eric Firing efiring at hawaii.edu
Sun Jul 25 18:04:25 EDT 2010


On 07/25/2010 11:32 AM, Gael Varoquaux wrote:
> On Sun, Jul 25, 2010 at 11:16:48AM -1000, Eric Firing wrote:
>> I haven't looked at mlab.show(), but if it is derived from earlier
>> matplotlib show(), then you might want to take a look at how show() is
>> now implemented in mpl.  It works well with ipython 0.10 and 0.11.
>
> Thanks Eric. mlab's show was not derived from any matplotlib code. None
> the less, I had a quite look at SVN matplotlib to figure out how it was
> done.
>
> It seems to me that it is done in 'backend_bases.py', line 81, by
> checking if IPython added a special attribute to the ShowBase instance.

Also, we don't start the mainloop in show() if mpl is in interactive 
mode.  Given that the input hook can take care of events, the remaining 
function of starting the mainloop is to block until all figures are 
closed.  So, show in non-interactive mode blocks; in interactive mode, 
it does not.

> Thus, it seems to rely on a collaboration between IPython and matplotlib.

Yes, in the sense that it takes advantage of that attribute if it is 
there; but no, in the sense that it works fine without IPython, or with 
plain IPython when the inputhook is in use.  It is not a clean solution 
to a general problem; it is an ad hoc solution to the specific problem 
of making mpl work under a reasonable range of current circumstances, 
including IPython 0.10 and 0.11 (assuming it doesn't change too much).

Eric

>
> Can anyone confirm or infirm?
>
> Cheers,
>
> Gaël




More information about the IPython-dev mailing list