06.02.20 14:58, Frank Millman пише:
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.

Do you import a common object *from* a module or import a module and access a common object as its attribute?

If the latter, the change may be related to
https://bugs.python.org/issue33331 . Modules are now cleaned up in the reversed order of importing.

In any case, the order of cleaning up modules is not specified/

--
https://mail.python.org/mailman/listinfo/python-list

Reply via email to