next up previous
Next: Plotting with matplotlib Up: IPython An enhanced Interactive Previous: IPython as a system

Subsections


Threading support

WARNING: The threading support is still somewhat experimental, and it has only seen reasonable testing under Linux. Threaded code is particularly tricky to debug, and it tends to show extremely platform-dependent behavior. Since I only have access to Linux machines, I will have to rely on user's experiences and assistance for this area of IPython to improve under other platforms.

IPython, via the -gthread and -wthread options (described in Sec. 5.1), can run in multithreaded mode to support pyGTK and WXPython applications respectively. Both of these GUI toolkits need to control the python main loop of execution, so under a normal Python interpreter, starting a pyGTK (or WXPython) application will immediately freeze the shell.

IPython, with one of these options (you can only use one at a time), separates the graphical loop and IPython's code execution run into different threads. This allows you to test interactively (with @run, for example) your GUI code without blocking.

Tk issues

As indicated in Sec. 5.1, a special -tk option is provided to try and allow Tk graphical applications to coexist interactively with WX or GTK ones. Whether this works at all, however, is very platform and configuration dependent. Please experiment with simple test cases before committing to using this combination of Tk and WX/GTK threading in a production environment.

Signals and Threads

When any of the thread systems (WX or GTK) are active, either directly or via -pylab with a threaded backend, it is impossible to interrupt long-running Python code via Ctrl-C. IPython can not pass the KeyboardInterrupt exception (or the underlying SIGINT) across threads, so any long-running process started from IPython will run to completion, or will have to be killed via an external (OS-based) mechanism.

To the best of my knowledge, this limitation is imposed by the Python interpreter itself, and it comes from the difficulty of writing portable signal/threaded code. If any user is an expert on this topic and can suggest a better solution, I would love to hear about it. In the IPython sources, look at the Shell.py module, and in particular at the runcode() method.


next up previous
Next: Plotting with matplotlib Up: IPython An enhanced Interactive Previous: IPython as a system
Fernando Perez 2005-01-28