Change in behaviour Python 3.7 > 3.8

Barry barry at barrys-emacs.org
Thu Feb 6 09:43:54 EST 2020



> On 6 Feb 2020, at 13:01, Frank Millman <frank at chagford.com> wrote:
> 
> 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.

I recall reading that shutdown had changed in 3.8, but cannot find the email/webpage that I read.

These days I assume that __del__ will almost never be useful and use exploit calls to tell an object I am finished with it and it can do its resource clean up.

Barry


> 
> Frank Millman
> 
> -- 
> https://mail.python.org/mailman/listinfo/python-list
> 



More information about the Python-list mailing list