Module deconstruction

Robin Becker robin at jessikat.fsnet.co.uk
Mon Aug 26 12:32:38 EDT 2002


I'm seeing strangeness when modules are being deconstructed. This is
with Sam Rushing's calldll and windll. 

the windll code has approximately the following structure

import calldll

class module:
        def __init__(self,name):
                self.handle = .....

        def __del__(self):
                calldll.free_library(self.handle)

        ......

map = {module('....'), ...}

is it reasonable that calldll.free_library appears to be None in the
__del__ method when the module is torn down. It seems as though calldll
is being destroyed before all uses are gone. If I replace the module
class __del__ with

        free_library = calldll.free_library
        def __del__(self):
                self.free_library(self.handle)

then things work as intended otherwise I see exceptions which are
ignored about Nonetype objects not being callable.
-- 
Robin Becker



More information about the Python-list mailing list