segfaults in ipython

Setting followups to matplotlib-devel

    > I get segfaults with ipython -pylab (and without the
    > flag) quite a bit as well. They usually seem pretty
    > random and frequent, but I found one way to reproduce.

    > gentoo-linux ipython-0.6.15 matplotlib-cvs

    > plot(rand(10)) a = gca() a.bbox<return> Segmentation
    > fault

    > This may not be a practical example, but it is the only
    > consistent one I can find right now.

Hey Charles,

Thanks for reporting this. I'm not sure this is related to Steve's
bug, but it's good to know about.

I can reproduce your crash on ubuntu, and only in ipython. This is
independent of backends and can be reproduced with this minimal script

    peds-pc311:~> python
    Python 2.4.1 (#2, Mar 30 2005, 21:51:10)
    [GCC 3.3.5 (Debian 1:3.3.5-8ubuntu2)] on linux2
    Type "help", "copyright", "credits" or "license" for more information.
    >>> from matplotlib.transforms import unit_bbox
    >>> b = unit_bbox()
    >>> b
    <Bbox object at 0x81e3a6c>
    >>>

but in ipython I get the segfault

    peds-pc311:~> ipython
    Python 2.4.1 (#2, Mar 30 2005, 21:51:10)
    Type "copyright", "credits" or "license" for more information.

    IPython 0.6.16_cvs -- An enhanced Interactive Python.
    ? -> Introduction to IPython's features.
    %magic -> Information about IPython's 'magic' % functions.
    help -> Python's own help system.
    object? -> Details about 'object'. ?object also works, ?? prints more.

    In [1]: from matplotlib.transforms import unit_bbox

    In [2]: b = unit_bbox()

    In [3]: b
    Segmentation fault

bbox is a pycxx extension object defined in src/_transforms.cpp

Something ipython is doing to represent the object is causing the
crash. I can do the following in ipython

    In [1]: from matplotlib.transforms import unit_bbox

    In [2]: b = unit_bbox()

    In [3]: print b
    <Bbox object at 0x82601c4>

    In [4]: str(b)
    Out[4]: '<Bbox object at 0x82601c4>'

Fernando, what kind of whacky magic are you doing when I type

    In [5]: b
    Segmentation fault

We've seen segfault's before when doing type inspection in pycxx; I've
reported this but haven't gotten any resolution
http://sourceforge.net/tracker/index.php?func=detail&aid=1210007&group_id=3180&atid=103180

JDH

John Hunter wrote:

but in ipython I get the segfault

    peds-pc311:~> ipython
    Python 2.4.1 (#2, Mar 30 2005, 21:51:10)
    Type "copyright", "credits" or "license" for more information.

    IPython 0.6.16_cvs -- An enhanced Interactive Python.
    ? -> Introduction to IPython's features.
    %magic -> Information about IPython's 'magic' % functions.
    help -> Python's own help system.
    object? -> Details about 'object'. ?object also works, ?? prints more.

    In [1]: from matplotlib.transforms import unit_bbox

    In [2]: b = unit_bbox()

    In [3]: b
    Segmentation fault

This one is going to be hard to track, since I can't reproduce it on my system (Fedora 3):

planck[~]> ip
Python 2.3.4 (#1, Feb 2 2005, 12:11:53)
Type "copyright", "credits" or "license" for more information.

IPython 0.6.16_svn -- An enhanced Interactive Python.
? -> Introduction to IPython's features.
%magic -> Information about IPython's 'magic' % functions.
help -> Python's own help system.
object? -> Details about 'object'. ?object also works, ?? prints more.

In [1]: from matplotlib.transforms import unit_bbox

In [2]: b = unit_bbox()

In [3]: b
Out[3]: <Bbox object at 0x965d6d4>

In [4]:

In [4]:
planck[~]> pylab

In [1]: from matplotlib.transforms import unit_bbox

In [2]: b = unit_bbox()

In [3]: b
Out[3]: <Bbox object at 0x893866c>

So neither plain ipython nor 'ipython -pylab' show me any sign of trouble here.

I'm afraid we'll have to debug this one by proxy, since I can't see any problem here. The code which is executed when output is to be printed is the __call__ method of the CachedOutput object. Look around line 476 in IPython/Prompts.py. Adding some print/debug statements to that function might shed some light.

One thing you could try is toggling %Pprint back and forth. This is the pretty printer used by ipython, which is part of the stdlib (module pprint). It might be triggering some problem in the underlying pycxx objects.

Cheers,

f

FYI, turning off pprint gets rid of the error. Will look into it more.

Fernando Perez wrote:

···

John Hunter wrote:

but in ipython I get the segfault

    peds-pc311:~> ipython
    Python 2.4.1 (#2, Mar 30 2005, 21:51:10)
    Type "copyright", "credits" or "license" for more information.

    IPython 0.6.16_cvs -- An enhanced Interactive Python.
    ? -> Introduction to IPython's features.
    %magic -> Information about IPython's 'magic' % functions.
    help -> Python's own help system.
    object? -> Details about 'object'. ?object also works, ?? prints more.

    In [1]: from matplotlib.transforms import unit_bbox

    In [2]: b = unit_bbox()

    In [3]: b
    Segmentation fault

This one is going to be hard to track, since I can't reproduce it on my system (Fedora 3):

planck[~]> ip
Python 2.3.4 (#1, Feb 2 2005, 12:11:53)
Type "copyright", "credits" or "license" for more information.

IPython 0.6.16_svn -- An enhanced Interactive Python.
? -> Introduction to IPython's features.
%magic -> Information about IPython's 'magic' % functions.
help -> Python's own help system.
object? -> Details about 'object'. ?object also works, ?? prints more.

In [1]: from matplotlib.transforms import unit_bbox

In [2]: b = unit_bbox()

In [3]: b
Out[3]: <Bbox object at 0x965d6d4>

In [4]:

In [4]:
planck[~]> pylab

In [1]: from matplotlib.transforms import unit_bbox

In [2]: b = unit_bbox()

In [3]: b
Out[3]: <Bbox object at 0x893866c>

So neither plain ipython nor 'ipython -pylab' show me any sign of trouble here.

I'm afraid we'll have to debug this one by proxy, since I can't see any problem here. The code which is executed when output is to be printed is the __call__ method of the CachedOutput object. Look around line 476 in IPython/Prompts.py. Adding some print/debug statements to that function might shed some light.

One thing you could try is toggling %Pprint back and forth. This is the pretty printer used by ipython, which is part of the stdlib (module pprint). It might be triggering some problem in the underlying pycxx objects.

Cheers,

f

Charles Moad wrote:

FYI, turning off pprint gets rid of the error. Will look into it more.

OK, that's a start. Try running the following at a command line, via plain python:

import pprint

from matplotlib.transforms import unit_bbox
b = unit_bbox()
print pprint.pformat(b)

This is what I get:

planck[~/test]> python pprint_bug.py
<Bbox object at 0x8f3c99c>

If you get a segfault, it means that there's a problem with those objects triggered by pprint.

As a temporary workaround, you can permanently disable pprint in your ipython sessions by setting

pprint 0

in your ~/.ipython/ipythonrc file.

Cheers,

f

I found this link, http://mail.python.org/pipermail/python-bugs-list/2004-November/026192.html. I am guessing Jon and I are using python2.4 and you are using 2.3?

- Charlie

Fernando Perez wrote:

···

Charles Moad wrote:

FYI, turning off pprint gets rid of the error. Will look into it more.

OK, that's a start. Try running the following at a command line, via plain python:

import pprint

from matplotlib.transforms import unit_bbox
b = unit_bbox()
print pprint.pformat(b)

This is what I get:

planck[~/test]> python pprint_bug.py
<Bbox object at 0x8f3c99c>

If you get a segfault, it means that there's a problem with those objects triggered by pprint.

As a temporary workaround, you can permanently disable pprint in your ipython sessions by setting

pprint 0

in your ~/.ipython/ipythonrc file.

Cheers,

f

Charles Moad wrote:

I found this link, http://mail.python.org/pipermail/python-bugs-list/2004-November/026192.html. I am guessing Jon and I are using python2.4 and you are using 2.3?

That's correct. I have 2.4 lying around, but matplotlib isn't built for it, nor are any of its dependencies. So I can only do mpl tests with 2.3, I'm afraid.

Cheers,

f

I would consider this a python bug, and I just added a quick fix for me.

Changed line 511 in Prompts.py to say
  if self.Pprint and hasattr(arg, '__repr__'):
instead of
  if self.Pprint:

You probably don't want to add this for everything, but would it be possible to override the display method of the CachedOutput when the pylab option is specified? Further, you could only do this for python v.2.4.

- Charlie

Fernando Perez wrote:

···

Charles Moad wrote:

I found this link, http://mail.python.org/pipermail/python-bugs-list/2004-November/026192.html. I am guessing Jon and I are using python2.4 and you are using 2.3?

That's correct. I have 2.4 lying around, but matplotlib isn't built for it, nor are any of its dependencies. So I can only do mpl tests with 2.3, I'm afraid.

Cheers,

f

Charles Moad wrote:

I would consider this a python bug, and I just added a quick fix for me.

Changed line 511 in Prompts.py to say
  if self.Pprint and hasattr(arg, '__repr__'):
instead of
  if self.Pprint:

You probably don't want to add this for everything, but would it be possible to override the display method of the CachedOutput when the pylab option is specified? Further, you could only do this for python v.2.4.

Since it's really a python bug, I'd rather see it fixed upstream than adding (yet another) hack in ipython to defend against it. But I also don't want ipython to crash for users, that's for sure.

Let's see if John can get his pycxx animals to grow a __repr__, which will fix the issue. If that doesn't work, I'll go ahead and stick in a version-specific defense layer into Prompts.py to at least help the ipython users, while python fixes the problem upstream.

Cheers,

f

The problem seems to be alleviated for me now from you latest commit, John.

Thanks,

Fernando Perez wrote:

···

Charles Moad wrote:

I would consider this a python bug, and I just added a quick fix for me.

Changed line 511 in Prompts.py to say
    if self.Pprint and hasattr(arg, '__repr__'):
instead of
    if self.Pprint:

You probably don't want to add this for everything, but would it be possible to override the display method of the CachedOutput when the pylab option is specified? Further, you could only do this for python v.2.4.

Since it's really a python bug, I'd rather see it fixed upstream than adding (yet another) hack in ipython to defend against it. But I also don't want ipython to crash for users, that's for sure.

Let's see if John can get his pycxx animals to grow a __repr__, which will fix the issue. If that doesn't work, I'll go ahead and stick in a version-specific defense layer into Prompts.py to at least help the ipython users, while python fixes the problem upstream.

Cheers,

f

Charles Moad wrote:

  The problem seems to be alleviated for me now from you latest commit, John.

OK, thanks for the info. I'll leave Prompts.py alone for now then.

Cheers,

f