Change in behaviour Python 3.7 > 3.8

Frank Millman frank at chagford.com
Thu Feb 6 07:58:34 EST 2020


Hi all

I have noticed a change in behaviour in Python 3.8 compared with 
previous versions of Python going back to at least 2.7. I am pretty sure 
that it is not a problem, and is caused by my relying on a certain 
sequence of events at shutdown, which of course is not guaranteed. 
However, any change in behaviour is worth reporting, just in case it was 
unintended, so I thought I would mention it here.

I have a module (A) containing common objects shared by other modules. I 
have a module (B) which imports one of these common objects - a set().

Module B defines a Class, and creates a global instance of this class 
when the module is created. This instance is never explicitly deleted, 
so I assume it gets implicitly deleted at shutdown. It has a __del__() 
method (only for temporary debugging purposes, so will be removed for 
production) and the __del__ method uses the set() object imported from 
Module A.

This has worked for years, but now when the __del__ method is called, 
the common object, which was a set(), has become None.

My assumption is that Module A gets cleaned up before Module B, and when 
Module B tries to access the common set() object it no longer exists.

I have a workaround, so I am just reporting this for the record.

Frank Millman



More information about the Python-list mailing list