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

Laurent Dufrechou laurent.dufrechou at gmail.com
Thu Feb 12 04:09:32 EST 2009


Hi Brian,

> > 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.
> 
> The IPython core cannot run user code in a thread (at least, not in a
> thread safe manner).  Here is the reason:
> 
> If there are wx/GUI objects in the IPython core that the user is
> working with (for plotting through matplotlib, etc/), both wx itself
> and user code can and will perform operations on those objects.
> Unless you protect all such operations with locks, you can easily get
> into trouble.  Summary:  a GUI enabled IPython has to be run in the
> same thread as the GUI itself.
> 
> Plus, I don't see what running the code in a thread buys you in this
> case.  In fact, because of the subtle interaction between signals and
> threads, I would even say that using threads makes things more
> complicated.  Each time user code is run, can't you just install a
> signal handler that will interupt the user code directly?
> 

Well, thx to asynchroneous raise in the thread I'm able to interrupt the
code.
Interaction is not that bad, just being careful when calling wx code inside
ipython.
So that's true that you can't run wx code into the shell currently.
That's why I'm looking for another possible solution.

> 
> 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.
> 
> I don't think you can send signals to threads - only processes.
> Fernando has hacked this type of thing before though, so he might know
> better.
> 

Yep you can, found a thread class to do that. Check ./gui/wx/thread_ex.py.
With this I'm able to raise asynchroneous interrupts.

> > 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.
> 
> I think you can, you may have to install your own signal handlers if
> wx/qt install their own (which they probably do).
>

Hum, will write to wx mailing list to see if it is possible to catch such
event, the problem I see
is that I'm processing the event 'enter' when running ipython loop. So not
sure another event can be catched at the same time asynchroneously :(






More information about the IPython-dev mailing list