[Pyrex] Tricky bug while unloading modules

Gustavo Sverzut Barbieri barbieri at gmail.com
Sat Nov 17 01:47:20 CET 2007


On Nov 16, 2007 7:11 PM, Robert Kern <robert.kern at gmail.com> wrote:
> Gustavo Sverzut Barbieri wrote:
> > Hi,
> >
> > I'm mailing both Cython and Pyrex as we use Cython, but 99% sure that
> > this problem also happens on Pyrex.
> >
> > In Python-EFL we have two modules that are related: evas and
> > ecore.evas. The former is a canvas and its objects, the latter is the
> > window that contains the canvas and its objects.
> >     The window (ecore.evas) have a reference to the canvas (evas) that
> > have reference to it's children. The C module will do the cascade
> > delete when the root is deleted, with proper callbacks to inform
> > object death.
> >
> > The problem happens when the window is not explicitly deleted by user
> > and the program ends: the module will be unloaded before the objects
> > are collected, but we have a call in the object dealloc that will use
> > a method (from another object), that requires a module python-string
> > to resolve the method. This string is NULL by that time, since
> > cleanup() was run on module unloading, making our software exit with
> > SEGV.
> >
> > To avoid the problem, we're forcing object's death with "del window",
> > but it would be nice to have this object delete+unload done right,
> > maybe force collection of module objects before unloading or something
> > in these lines. I'm not sure what's the proper way to fix this.
>
> If you would like to register cleanup functions to run before modules start
> going away, use the atexit module.

Yes, I'm aware of atexit module, but unfortunately this is not the
problem. The problem, as I described, is related to C-Python
interpreter calling the garbage collector _after_ it called module's
cleanup function. My object's method to be called by GC will use
module variable (indirectly, in my case it's a string that cython
caches as a global object), that is now NULL, giving this value to
GetAttr.

-- 
Gustavo Sverzut Barbieri
--------------------------------------
Jabber: barbieri at gmail.com
   MSN: barbieri at gmail.com
  ICQ#: 17249123
 Skype: gsbarbieri
Mobile: +55 (81) 9927 0010



More information about the Pyrex mailing list