[Pyrex] Tricky bug while unloading modules

Robert Kern robert.kern at gmail.com
Fri Nov 16 23:11:54 CET 2007


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.

-- 
Robert Kern

"I have come to believe that the whole world is an enigma, a harmless enigma
 that is made terrible by our own mad attempt to interpret it as though it had
 an underlying truth."
  -- Umberto Eco




More information about the Pyrex mailing list