Will python ever have signalhandlers in threads?

Fernando Perez fperez528 at yahoo.com
Sat Nov 13 01:40:20 CET 2004

Jean Brouwers wrote:

> Fernando,
> Just curious, does 'gtk/WX' in your message below mean wxPython?


> If so, does this signal handling code actually work with wxPython?> 

It does, but not in a generic manner: this is code for ipython to support
matplotlib's WX backend in an interactive shell.  It allows you to type into
ipython plotting commands which cause matplotlib to open a WX plotting window,
and the interactive terminal continues to function.  You can have multiple WX
plotting windows open, and the command line keeps on chugging.

But this relies on a special collaborative hack between matplotlib and ipython.
matplotlib, in its WX and GTK backends (Tk doesn't need this) has a special
flag to indicate who is in control of the mainloop.  In standalone scripts,
everything works in the typical manner.  But if ipython comes in, it will set
this flag, telling matplotlib to keep off the mainoop.

It's pretty hackish, but it works in practice pretty well.  

here's the relevant matplotlib WX code (trimmed of docstring):

def show():

    for figwin in Gcf.get_all_fig_managers():

    if show._needmain and not matplotlib.is_interactive():
        show._needmain = False
show._needmain = True

When ipython starts up, it sets show._needmain to False, so that the Mainloop()
call is never made.  You can look at the whole code from ipython if you wish,
it's in IPython/Shell.py.



More information about the Python-list mailing list