Antoine Pitrou added the comment:

Well, let's call it a limitation rather than a bug.
When creating a global variable (such as "a" in your example), that variable is 
kept alive at least as long as the module containing it. However, modules 
usually live until very late in the interpreter shutdown process, *especially* 
the __main__ module. So, by the time "a" gets garbage-collected, other globals 
or modules may already have been wiped.

Unfortunately, I don't think there's much we can do to improve this. The answer 
to your specific problem is to use the atexit module instead, since an atexit 
callback is guaranteed to be called with a normal execution environment, before 
it starts being garbage-collected.

----------
status: pending -> open

_______________________________________
Python tracker <rep...@bugs.python.org>
<http://bugs.python.org/issue21512>
_______________________________________
_______________________________________________
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com

Reply via email to