I reproduced this. Interesting behavior for sure. One thing that you need to realize is that __del__ not guaranteed even when called upon exiting the interpreter. There is also no specific order for completing objects at the output of the interpreter.
As you exit the interpreter, there is no guarantee that os not deleted first. In this case, it seems that os actually terminates before your Logger object. This probably happens depending on the order in the globals dictionary.
If we just type the globals dictionary keys right before we exit:
for k in globals().keys(): print k
you will see:
temp_test_path __builtins__ __file__ __package__ __name__ Logger os __doc__ logger
or
logger __builtins__ __file__ __package__ temp_test_pat __name__ Logger os __doc__
Pay attention to where your Logger is located, especially compared to where os is in the list. With temp_test_pat , Logger actually terminates First , so os is still tied to something meaningful. However, it gets finalized last if temp_test_path used.
If you plan to live in real time until the interpreter exits, and you have a cleaning code that you want to run, you can always register a function that will be launched using atexit.register .
mgilson
source share