Order of prints when deleting object references in Python
I create an object using a class. The class has a __del__ method. I then create an alias to the object variable. I then delete the 2 variable references to the object. After this has happened Python automatically calls __del__ but in the Python shell, prints from __del__ appear before other top-level prints. Is this because __del__ is run as a higher priority thread than top-level prints? class MyClass: def __del__(self): print("Object finalized") obj1 = MyClass() obj2 = obj1 del obj1 print("First reference removed") del obj2 print("Second reference removed") Shell output: First reference remo
0 upvotes
View original discussion ↗
Comments
Sign in or sign up to comment and upvote.
No comments yet.