summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorTim Peters <tim.peters@gmail.com>2006-04-17 21:12:33 (GMT)
committerTim Peters <tim.peters@gmail.com>2006-04-17 21:12:33 (GMT)
commitc7605f21ae5c5b9e695c8a2346bc21357a84c6b3 (patch)
treed4b71e7b27be31adbb9f1d059df274aaa1e645bf
parentab1d245871466b308ef9d015702a77b8262759c4 (diff)
downloadcpython-c7605f21ae5c5b9e695c8a2346bc21357a84c6b3.zip
cpython-c7605f21ae5c5b9e695c8a2346bc21357a84c6b3.tar.gz
cpython-c7605f21ae5c5b9e695c8a2346bc21357a84c6b3.tar.bz2
local.__del__(): This didn't actually do anything, because of too
much convolution <0.5 wink>. Simplified to the point that it works, and test_threading_local no longer reports leaks under -R. Thanks to Thomas Wouters for initial analysis.
-rw-r--r--Lib/_threading_local.py53
-rw-r--r--Misc/NEWS3
2 files changed, 27 insertions, 29 deletions
diff --git a/Lib/_threading_local.py b/Lib/_threading_local.py
index 90717a8..1350ddf 100644
--- a/Lib/_threading_local.py
+++ b/Lib/_threading_local.py
@@ -133,7 +133,7 @@ affects what we see:
>>> del mydata
"""
-# Threading import is at end
+from threading import currentThread, RLock, enumerate
class _localbase(object):
__slots__ = '_local__key', '_local__args', '_local__lock'
@@ -203,35 +203,30 @@ class local(_localbase):
lock.release()
- def __del__():
- threading_enumerate = enumerate
- __getattribute__ = object.__getattribute__
+ # The default argument is a hack, to give __del__ a local name for
+ # threading.enumerate (sidestepping problems with Python None'ing-out
+ # module globals at shutdown time).
+ def __del__(self, _threading_enumerate=enumerate):
- def __del__(self):
- key = __getattribute__(self, '_local__key')
+ key = object.__getattribute__(self, '_local__key')
+ try:
+ threads = list(_threading_enumerate())
+ except:
+ # If enumerate fails, as it seems to do during
+ # shutdown, we'll skip cleanup under the assumption
+ # that there is nothing to clean up.
+ return
+
+ for thread in threads:
try:
- threads = list(threading_enumerate())
- except:
- # if enumerate fails, as it seems to do during
- # shutdown, we'll skip cleanup under the assumption
- # that there is nothing to clean up
- return
-
- for thread in threads:
- try:
- __dict__ = thread.__dict__
- except AttributeError:
- # Thread is dying, rest in peace
- continue
-
- if key in __dict__:
- try:
- del __dict__[key]
- except KeyError:
- pass # didn't have anything in this thread
+ __dict__ = thread.__dict__
+ except AttributeError:
+ # Thread is dying, rest in peace.
+ continue
- return __del__
- __del__ = __del__()
-
-from threading import currentThread, enumerate, RLock
+ if key in __dict__:
+ try:
+ del __dict__[key]
+ except KeyError:
+ pass # didn't have anything in this thread
diff --git a/Misc/NEWS b/Misc/NEWS
index 9439813..2af8616 100644
--- a/Misc/NEWS
+++ b/Misc/NEWS
@@ -72,6 +72,9 @@ Extension Modules
Library
-------
+- The ``__del__`` method of class ``local`` in module ``_threading_local``
+ returned before accomplishing any of its intended cleanup.
+
- Patch #790710: Add breakpoint command lists in pdb.
- Patch #1063914: Add Tkinter.Misc.clipboard_get().