Is Object.__del__(self) The Most Appropriate Place To Flush A Logging Class?
I have a custom logging class for my Python script with a flush() method which print()s the contents of a list. I would like to include flush() in the special __del__() method in c
Solution 1:
You might want to look into making this logger a context manager. That still will not flush in the case of abnormal termination, but few things will. But __del__
might not be called on objects even in normal termination.
Loggers might be one of the things that doesn't fit well when using the with
statement, as they are quite global, so it's not sure context manager is a good fit.
Post a Comment for "Is Object.__del__(self) The Most Appropriate Place To Flush A Logging Class?"