[IPython-dev] ctrl+c in gui, event loops, sure i'm missing something...

Laurent Dufrechou laurent.dufrechou at gmail.com
Wed Feb 11 17:05:34 EST 2009


Hi guys, want to have a reflexion with the gui gurus over there ;)

Since i've written my wx ipython gui I've wanted from the beginning to
support ctrl+c.
Because it is so easy to do a code that lock it is i think a must have feature.
My gui run a wx main loop. A specific widget is created to instanciate
a scintilla textctrl. An ipython object is also created that handle
the current state of the ipython interpreter.
when the user push enter, as in ipython console application I push the
line in the interpreter and this one run the code loop.
Here is how i solved the problem:

If user want to have ctrl+c support, I has to activate a "threading option".
When this option is activated each time a line is pushed in the
interpreter the line is pushed in thread code executor that makes the
ipython core run the line  in a little tread. When the line is
processed, the result is displayed and the thread killed.
If user launched an infinite loop:
while 1:
  a=1

then I can catch the ctrl+c key becuase my gui still responsive and i
send a ctrl+c to the thread. That's all and it works well so far.

Now that i'm much satisfisfied with current state, i want to improve
the whole reflexion a step further.
In ipython console (in bash) you can easily do a ctrl+c.
WHY CAN'T I do that without threading in a gui... It could be easily
removed if the could get the ctrl+c and then send it to the gui to
make it stop.

So is there a way perhaps to do it the other way, that is:
make the gui run the ipython line and get another "event magic loop"
in another thread to catch the ctrl+c and send it to wx.mainloop?
(do it the other way in fact :)) so it will remove all the thread
constraint of my code regarding ipython integration. Well there is not
a lot of constraints but...

The fact is that i'm not aware of how the wx/qt/... event loop works
and perhaps someone there has better idea ?

Any clever magic idea welcomed!

Cheers,
Laurent



More information about the IPython-dev mailing list