Deleting objects in Python 1.6

Michael Hudson mwh21 at cam.ac.uk
Thu May 4 08:30:39 EDT 2000


"Thomas A. Bryan" <tbryan at python.net> writes:

> Michael Hudson wrote:
> > 
> > Try this:
> > 
> > >>> l=[[]]
> > >>> m=l[0]
> > >>> for i in range(100000):
> > ...     m.append([])
> > ...     m = m[0]
> > ...
> > >>> del l
> > 
> > (hint: it segfaults on my machine, unless I use a v. new Python)
> 
> Interesting.  I caused Python to segfault once on Solaris.  I wonder 
> whether this problem was the cause.

There are easier ways of crashing Python 1.5.2; 

>>> l=[]
>>> m=[]     
>>> l.append(l)
>>> m.append(m)
>>> l==m
Segmentation fault (core dumped)

is probably the simplest (and also won't work on 1.6).

>>> import marshal
>>> l=[]          
>>> l.append(l)
>>> marshal.dumps(l)
Segmentation fault (core dumped)

is another... any C code that traverses structure "deeply" is at risk
from recursive structures.

>  Then again, your code works on 
> my little Linux box...

Tried it again.  Still crashes.  Gotta love computers, no?

I guess you have to grow the stack until it stomps on something else,
which might depend on all sorts of factors, like how many modules you
have loaded, total memory size, versions of the kernel, phase of the
moon, that kind of thing.

Have you tried increasing the depth of the structure?

Cheers,
M.

-- 
93. When someone says "I want a programming language in which I
    need only say what I wish done," give him a lollipop.
     -- Alan Perlis, http://www.cs.yale.edu/~perlis-alan/quotes.html



More information about the Python-list mailing list