cleanup order

Bjorn Pettersen bjorn at roguewave.com
Wed Jul 5 18:05:50 EDT 2000


Johannes Zellner wrote:
> 
> Hi,
> 
> suppose I've
> 
>     # fred provides `fun'
>     import fred
> 
>     class Lola:
>         def __init__(self, x):
>             self.x = x
>         def __del__(self):
>             fred.fun(self.x)
> 
>     x = Lola('hello')
>     # end of script
> 
> this doesn't work, because fred is not present any more
> when x is destroyed. I don't know anything about python's
> internals, but I guess the dynamical loaded shared object's
> function table is destroyed (somehow) before x is destroyed.
> 
> Any comments ? (or even workarounds ?)

This should work:

   ...
   def __del__(self, fun=fred.fun):
      fun(self.x)

it's using a default argument to make sure the reference count to
fred.fun doesn't reach zero until the Lola instance is deleted.

-- bjorn




More information about the Python-list mailing list