[IPython-dev] Re: [SciPy-dev] Generic gui_thread + IPython: solution already exists!
prabhu_r at users.sf.net
Sun Nov 14 21:26:33 EST 2004
>>>>> "PP" == Pearu Peterson <pearu at scipy.org> writes:
PP> On Mon, 15 Nov 2004, Prabhu Ramachandran wrote:
PP> With wx 126.96.36.199 I get:
PP> In : cd /opt/src/wxPythonSrc-188.8.131.52/wxPython/demo
PP> In : import Main
PP> In : d = Main.wxPythonDemo(None, -1, 'a') 22:39:45:
PP> AssertionError: No wxApp created yet
Looks like you did not start IPython with the -pylab option? wxApp is
created if you use -pylab (AND set WX as your default backend in
.matplotlibrc, I forgot to add this detail). Mine looks like this::
backend : WX
interactive : True
Put this in a file called ~/.matplotlibrc and start IPython like so::
$ ipython -pylab
then try again. Thanks!
>> Now, obviously, no other application can launch a mainloop. So
>> we need to somehow inhibit the user from being able to start
>> it. The solution is incredibly simple, replace the real
>> mainloop with a dummy.
PP> Could this be used in gui_thread? Do we need gui_thread
gui_thread can hang around FWIW. The solution I am discussion will
only work with IPython. Not with vanilla Python or with IDLE etc. I
don't use these so this is not an issue but I think gui_thread can be
left as it is (with some simple cleanup perhaps). This is one more
reason why IPython should be the default Python shell for anyone who
uses Python interactively. :)
The approach Fernando uses is identical to what is done in the
gpython.py shell used to run pyGTK interactively. A wxApp or
gtk.mainloop() is run in a background thread and *everything* typed by
the user is run in it. IPython grabs whatever the user types and then
sends this off to the second thread and executes it there. Thus,
things are always done in the right thread and there are no issues.
The only problem is exceptions, signal handlers etc. It looks like
exceptions are trapped nicely and passed back to the main thread. I
don't know about the signal handlers.
More information about the IPython-dev