[Pyrex] Tricky bug while unloading modules

Robert Bradshaw robertwb at math.washington.edu
Sat Nov 17 02:20:31 CET 2007


On Nov 16, 2007, at 5:05 PM, Greg Ewing wrote:

> Gustavo Sverzut Barbieri wrote:
>
>> (indirectly, in my case it's a string that cython
>> caches as a global object)
>
> What exactly is this string, and how does it get cached?

Some clarification here: I think this is a cython only bug. I would  
guess (based on the comments so far) that the string getting cached  
is an interned string in the module. As far as I can tell, cython  
modules are never actually unloaded when Python exits, and so  
interned strings and global variables are never freed. To facilitate  
memory debugging, we deallocate these things when Python exits in a  
module-level cleanup() function. If modules are deallocated in the  
wrong order, bad things can happen.

The fix is to either register a function to del the problem manually  
with atexit, or to compile the files with a cleanup level of 0 (in  
Options.py).

- Robert




More information about the Pyrex mailing list