[IPython-user] Segmentation fault with -pylab

Fernando Perez Fernando.Perez at colorado.edu
Wed Nov 3 19:45:37 CST 2004


Hi Francesc,

Francesc Alted schrieb:

> Thanks for the patch. It seems to work well for me. However, I must confess
> that the behaviour looks a bit weird to my eyes. I'm very used to press ^C
> when I don't want to execute the line I'm editing (both in ipython or bash
> or whatever), as a rapid way to get the prompt back again. However, with
> your patch, I need to press an additional 'Return', and more regrettably,
> the command line that I was composing and trying to throw out is executed
> against my will (!)
> 
> I hope this is not going to stay 'as is', otherwise my brain could become
> severly damaged ;) 

OK, your point is very valid.  I've just committed a modified version into 
CVS, which improves things somewhat.  However, it's based on a horrendous 
hack, because I don't know enough about cross-thread exception handling to 
solve this cleanly (and from the threads on c.l.py, this topic is pretty much 
deep, black voodoo for even fairly seasoned python experts).

My hackish solution has several drawbacks:

1. It only works if readline is available.

2. It still requires the 'press Enter' step.

3. It marks the line which was canceled with IPythonIgnoreLine.  Basically ANY 
line which has this gets ignored.  So if you cancel a line and up-arrow, 
you'll get this special marker, which you'll have to remove manually if you 
wish to re-execute the line.  I made it one word so that at least you could 
wipe it out with a simple Alt-Backspace, but this is still ugly.

Here's an example:

planck[IPython]> pylab

In [1]: print 'hello'
hello

In [2]: print 'hello'
KeyboardInterrupt - Press <Enter> to continue.

In [3]: print 'hello' IPythonIgnoreLine

In [4]:  ## note that the above line got ignored, b/c I didn't remove the marker

I know that this is far from ideal, but unfortunately all my attempts at a 
clean solution failed.  The problem is being able to trap a KeyboardInterrupt 
from the right thread, both in GTK and WX.  I have simply no idea how to do 
it.  If anyone can take a stab at this and send a better solution, I'll gladly 
include it.

But while ugly, at least this solution satisfies several constraints:

1. it traps Ctrl-C correctly

2. It does NOT execute the canceled line


Note that if you hit Ctrl-C in the middle of the line, it's even uglier:

In [4]: print 'hello'
hello

In [5]: print 'hello'
KeyboardInterrupt - Press <Enter> to continue.

In [6]: print 'he IPythonIgnoreLine llo'

The ignore marker gets put by readline wherever your cursor is.

This is a really, really unpleasant hack.  I'll try to find something better, 
but so far my experience with threads has been so frustrating that I'm not too 
optimistic.

I would appreciate if you could test it (and even better if you have a clean 
solution :)

Best,

f




More information about the IPython-user mailing list