super not working in __del__ ?

Jeff Epler jepler at unpythonic.net
Tue Feb 15 20:47:27 EST 2005


When a Python program exits, various steps of cleanup occur.  One of
them is that each entry in the __dict__ of each module is set to 'None'.
Imagine that your __del__ runs after this step of the cleanup.  The reference
to the module-level variable that names your class is no longer available

I looked around at the documentation and didn't immediately find where
this is documented.  The closest I saw was in the C API reference:
    void Py_Finalize(   )
        Undo all initializations made by Py_Initialize() and subsequent use of
        Python/C API functions, and destroy all sub-interpreters (see
        Py_NewInterpreter() below) that were created and not yet destroyed
        since the last call to Py_Initialize(). Ideally, this frees all memory
        allocated by the Python interpreter. This is a no-op when called for a
        second time (without calling Py_Initialize() again first). There is no
        return value; errors during finalization are ignored.

        This function is provided for a number of reasons. An embedding
        application might want to restart Python without having to restart the
        application itself. An application that has loaded the Python
        interpreter from a dynamically loadable library (or DLL) might want to
        free all memory allocated by Python before unloading the DLL. During a
        hunt for memory leaks in an application a developer might want to free
        all memory allocated by Python before exiting from the application.

*       Bugs and caveats: The destruction of modules and objects in modules is
*       done in random order; this may cause destructors (__del__() methods) to
*       fail when they depend on other objects (even functions) or modules.
        Dynamically loaded extension modules loaded by Python are not unloaded.
        Small amounts of memory allocated by the Python interpreter may not be
        freed (if you find a leak, please report it). Memory tied up in
        circular references between objects is not freed. Some memory allocated
        by extension modules may not be freed. Some extensions may not work
        properly if their initialization routine is called more than once; this
        can happen if an application calls Py_Initialize() and Py_Finalize()
        more than once. 
but this doesn't go into detail about exactly how modules are cleaned up.

If anybody knows if this is better-documented somewhere, please speak
up!

Jeff
-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 196 bytes
Desc: not available
URL: <http://mail.python.org/pipermail/python-list/attachments/20050215/638aeb23/attachment.sig>


More information about the Python-list mailing list