here is a proposition of a new strategy for interactive plotting in GTK (probably also WX), that doesn't need IPython, and runs the mainloop in a separate thread from the calculations.
It has no impact on the user unless he chooses to make use of it, and a small impact on the backend developper.
It works in two parts:
matplotlib/__init__.py imports a gtk_protect function that returns a wrapper around "dangerous" functions or methods.
The one proposed here (protect_mutex.py) encloses the actual function call in a gtk.threads_enter() / gtk.threads_leave() pair in order to acquire the GTK mutex.
The same strategy seems possible in WX, though I encountered a lot of annoying little problems with WX 2.4. If someone is interested in taking over that part, please ask me (I usually don't use WX).
For the non-interactive case, matplotlib defines a dummy gtk_protect function which returns its own input, i.e. nothing is changed in that case.
Then all the backend as to do is call gtk_protect on dangerous functions or methods in order to replace them with a wrapper. The wrapper has little overhead, so I may have protected more than needed.
How to use:
after applying the patch, you have to change your rc params to actually use it. Change your .matplotlibrc to contain the following:
backend : GTKAgg # or GTK or GTKCairo
interactive : True
gui_protect : Mutex
Afterwards, you can run most of the examples with python -i, and modify the plots to your liking
gui.diff (18.9 KB)