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 case the program ends without the log being flushed. However a note in the documentation states:
[...] when del() is invoked in response to a module being deleted (e.g., when execution of the program is done), other globals referenced by the del() method may already have been deleted or in the process of being torn down (e.g. the import machinery shutting down).
Would anyone recommend a different way of doing this, and if so, why?