[IPython-dev] Strange bug

Fernando Perez fperez.net at gmail.com
Mon Jan 8 11:58:14 CST 2007

[ This was meant originally for the list, resending ]

On 1/7/07, Gregory Novak <novak at ucolick.org> wrote:

> In the meantime, I have another strange IPython specific bug.  This
> uses GDL (http://gnudatalanguage.sourceforge.net/), an independent
> implementation of the IDL syntax.  (I'd like to have two independent
> solutions so my calling-IDL-from-python problem in case one of them
> ends up giving me trouble for one reason or another).  GDL allows
> itself to be built as a python module, and then you can do things
> like:
> >>> import GDL
> >>> print GDL.function("sin",(1,))
> 0.841470956802

Mmh, this one is not ipython-specific.  I get the same crash under
Ubuntu Edgy with 2.4.4 using pure python (not ipython).  The following
is running python under gdb:

>>> import GDL
>>> print GDL.function("sin",(1,))

Program received signal SIGSEGV, Segmentation fault.
[Switching to Thread 1075537584 (LWP 1616)]
0x40026bd9 in initreadline () from /usr/lib/python2.4/lib-dynload/readline.so
(gdb) bt
#0  0x40026bd9 in initreadline () from
#1  0x080f9a5b in PyOS_Readline ()
#2  0x08057549 in PyTokenizer_FromString ()
#3  0x08057cbd in PyTokenizer_Get ()
#4  0x08055dac in Py_Main ()
#5  0x080dd277 in PyRun_InteractiveOneFlags ()
#6  0x080dd466 in PyRun_InteractiveLoopFlags ()
#7  0x080ddf72 in PyRun_AnyFileExFlags ()
#8  0x08055cc2 in Py_Main ()
#9  0x08055132 in main ()

It very much seems like you've found a bug in readline related to
threads issues, which doesn't surprise me terribly.  Other ipython
users have in the past found similar bugs, which did get fixed:


The reason why for you plain python doesn't crash is because your
plain python session is not initializing readline at all, which I do
via my $PYTHONSTARTUP.  Here's how to crash plain python (at least it
works reliably on my ubuntu box).  Paste this into an interactive
session (don't try to execfile, you have to paste it as if you had
typed it interactively so readline has to work):

import os
import readline

''' Some gibberish here is needed that's long enough to trigger the bug.  I'm
not sure how much data is actually required...

12jd lsjlksajsa jfl;ksaj34567890
123asdjf lkasdj flkajs l;kfd4567890
123asdflkasdj fl;saj f;a4567890
12jd lsjlksajsa jfl;ksaj34567890
123asdjf lkasdj flkajs l;kfd4567890
123asdflkasdj fl;saj f;a4567890
12jd lsjlksajsa jfl;ksaj34567890
123asdjf lkasdj flkajs l;kfd4567890
123asdflkasdj fl;saj f;a4567890

   __histfile = os.path.join(os.environ['HOME'],'.python-history')
except IOError:
   pass  # History file doesn't exist yet.

# This will now cause a crash:

import GDL
print GDL.function("sin",(1,))


At this point, I get a segfault, so it's safe to say we have a python
bug here, not an ipython one.  IPython just happens to activate so
much of readline at startup that it forces the bug to the surface.

A good rule of thumb is: if you see a segfault, it's not an ipython
bug (except under Windows).  IPython has no extension code, so by
itself in principle it can't segfault.  It may /expose/ python bugs
(such as in this case, and it has happened before), but it can't cause
them by itself.

This statement is qualified because under windows, IPython's readline
support uses ctypes, and once you load ctypes, it's trivial to
segfault python with 'pure python', since at that point you're really
hooking directly into C libs and have bypassed all of the safeties of
the Python VM.



More information about the IPython-dev mailing list