N
Neal Becker
To implement logging, I'm using a class:
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, even though I believe my
program exits normally. What's wrong?
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, even though I believe my
program exits normally. What's wrong?