[IPython-dev] Threads and Ctrl-C
hans_meine at gmx.net
Thu Aug 18 10:53:21 CDT 2005
I don't know how many of you are actually working with IPython and GUI threads
- from my traceback experiences, I seem to be rather alone with my
strugglings. (I guess other toolkits than Qt - which I use - should have
similar problems, but I might be wrong.)
OK, try this:
Start "ipython -qthread", enter:
In : import time
In : for i in range(60): time.sleep(1)
Now press Ctrl-C, you will get a nice message "KeyboardInterrupt - Press
<Enter> to continue." which is more or less meaning "I don't know what to do
with your keypress, since I am totally unaware that the other thread might be
executing some code".
In the before-mentioned Qt Python shell we wrote at our lab, we had a similar
situation (probably Toni will be interested in this), but we actually had two
separate processes for the GUI and Python, mostly to solve exactly this
single Ctrl-C problem: As long as Python is doing something, the Ctrl-C
event would not get through to the GUI event handler, so the event handler
could not interrupt the interpreter.
Ullrich Köthe's solution was to write a small "interrupt" module that is
triggered from the other process via a socket and interrupts the interpreter
by calling PyErr_SetInterrupt(). It's not too large; I attached it for your
inspiration. IMHO having the possibility to interrupt some loop you
accidentally started with wrong parameters is a crucial feature?!
-------------- next part --------------
A non-text attachment was scrubbed...
Size: 4194 bytes
Desc: not available
Url : http://projects.scipy.org/pipermail/ipython-dev/attachments/20050818/92614b41/attachment.bin
More information about the IPython-dev