crash from __del__ method at script end

Bug #175295 reported by Hans Terlouw
2
Affects Status Importance Assigned to Milestone
Cython
Fix Released
Undecided
robertwb

Bug Description

Version 0.9.6.9. -- 0.9.6.7 didn't have this problem.
Python versions 2.3, 2.4 and 2.5.
Operating systems Fedora Core 4 and Fedora 8.

When the __del__ is called at script end by Python and this method refers to an attribute, Python crashes with a segmentation violation. When the __del__ method is called from within the script, it behaves normally. Example code below:

tdel.pyx:

class myclass(object):
   def __init__(self):
      self.myattr = 'my attribute'

   def show(self):
      print 'from show() :', self.myattr

   def __del__(self):
      print 'from __del__() :', self.myattr

The following script crashes at the end:

#!/bin/env python
import tdel
t = tdel.myclass()
t.show()

When the statement 'del t' is added at the end, it runs and exits normally.

Debugger information:

__pyx_1 = PyObject_GetAttr(__pyx_v_self, __pyx_n_myattr);

(gdb) print __pyx_n_myattr
$2 = (PyObject *) 0x0

It appears that the pointer to the attribute has become zero.

Revision history for this message
robertwb (robertwb) wrote : Re: [Bug 175295] crash from __del__ method at script end

This is an error when the "cleanup" functionality cleans up a module
before all instances of its types are gone. Change the cleanup level
in Options.py to 0 and it should go away. (I'm thinking of making
this the default.)

- Robert

On Dec 10, 2007, at 5:36 AM, Hans Terlouw wrote:

> Public bug reported:
>
> Version 0.9.6.9. -- 0.9.6.7 didn't have this problem.
> Python versions 2.3, 2.4 and 2.5.
> Operating systems Fedora Core 4 and Fedora 8.
>
> When the __del__ is called at script end by Python and this method
> refers to an attribute, Python crashes with a segmentation violation.
> When the __del__ method is called from within the script, it behaves
> normally. Example code below:
>
> tdel.pyx:
>
> class myclass(object):
> def __init__(self):
> self.myattr = 'my attribute'
>
> def show(self):
> print 'from show() :', self.myattr
>
> def __del__(self):
> print 'from __del__() :', self.myattr
>
> The following script crashes at the end:
>
> #!/bin/env python
> import tdel
> t = tdel.myclass()
> t.show()
>
> When the statement 'del t' is added at the end, it runs and exits
> normally.
>
> Debugger information:
>
> __pyx_1 = PyObject_GetAttr(__pyx_v_self, __pyx_n_myattr);
>
> (gdb) print __pyx_n_myattr
> $2 = (PyObject *) 0x0
>
> It appears that the pointer to the attribute has become zero.
>
> ** Affects: cython
> Importance: Undecided
> Status: New
>
> --
> crash from __del__ method at script end
> https://bugs.launchpad.net/bugs/175295
> You received this bug notification because you are a member of Cython-
> dev, which is the bug contact for Cython.

Revision history for this message
Hans Terlouw (j-p-terlouw) wrote :

robertwb wrote:
> This is an error when the "cleanup" functionality cleans up a module
> before all instances of its types are gone. Change the cleanup level
> in Options.py to 0 and it should go away. (I'm thinking of making
> this the default.)

This helped. Thanks!

Hans

robertwb (robertwb)
Changed in cython:
assignee: nobody → robertwb
status: New → Fix Committed
robertwb (robertwb)
Changed in cython:
status: Fix Committed → Fix Released
To post a comment you must log in.
This report contains Public information  
Everyone can see this information.

Other bug subscribers

Remote bug watches

Bug watches keep track of this bug in other bug trackers.