global destructor not called?

Bruno Desthuilliers bruno.42.desthuilliers at wtf.websiteburo.oops.com
Fri Jun 15 11:50:36 EDT 2007


Neal Becker a écrit :
> To implement logging, I'm using a class:

If I may ask : any reason not to use the logging module in the stdlib ?

> class logger (object):
>     def __init__ (self, name):
>         self.name = name
>         self.f = open (self.name, 'w')
>     def write (self, stuff):
>         self.f.write (stuff)
>     def close (self):
>         self.f.close()
>     def flush (self):
>         self.f.flush()
>     def reopen (self):
>         self.f.flush()
>         self.f.close()
>         os.rename (self.name, self.name + '.old')
>         self.f = open (self.name, 'w')
>     def __del__ (self):
>         try:
>             os.remove (self.name + '.old')
>         except:
>             pass
> 
> And setting:
> sys.stderr = logger(...)
> 
> It seems my cleanup (__del__) is never called,

What makes you think so ?

> even though I believe my
> program exits normally.  What's wrong?

Not enough data...



More information about the Python-list mailing list