Bruno Desthuilliers wrote: > 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 ?
Don't exactly recall, but needed some specific behavior and it was just easier this way. > >> 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 ? Cleanup should remove file file '.old', and it wasn't removed. Adding atexit.register (self.__del__) to the logger constructor DID fix it. > >> even though I believe my >> program exits normally. What's wrong? > > Not enough data... -- http://mail.python.org/mailman/listinfo/python-list