cpython: d6ad9d7468f7 (original) (raw)
Mercurial > cpython
changeset 84057:d6ad9d7468f7
Issue #15528: Delay importing atexit until weakref.finalize() used. [#15528]
Richard Oudkerk shibturn@gmail.com | |
---|---|
date | Sat, 08 Jun 2013 16:52:29 +0100 |
parents | 0be613638523 |
children | d1b5e41acf28 |
files | Lib/weakref.py |
diffstat | 1 files changed, 7 insertions(+), 3 deletions(-)[+] [-] Lib/weakref.py 10 |
line wrap: on
line diff
--- a/Lib/weakref.py +++ b/Lib/weakref.py @@ -23,7 +23,6 @@ from _weakrefset import WeakSet, _Iterat import collections # Import after _weakref to avoid circular import. import sys import itertools -import atexit ProxyTypes = (ProxyType, CallableProxyType) @@ -464,11 +463,18 @@ class finalize: _shutdown = False _index_iter = itertools.count() _dirty = False
class _Info: slots = ("weakref", "func", "args", "kwargs", "atexit", "index") def init(self, obj, func, *args, **kwargs):
if not self._registered_with_atexit:[](#l1.21)
# We may register the exit function more than once because[](#l1.22)
# of a thread race, but that is harmless[](#l1.23)
import atexit[](#l1.24)
atexit.register(self._exitfunc)[](#l1.25)
finalize._registered_with_atexit = True[](#l1.26) info = self._Info()[](#l1.27) info.weakref = ref(obj, self)[](#l1.28) info.func = func[](#l1.29)
@@ -569,5 +575,3 @@ class finalize: finalize._shutdown = True if reenable_gc: gc.enable() - -atexit.register(finalize._exitfunc)