mirror of
https://github.com/python/cpython.git
synced 2025-09-14 04:37:29 +00:00
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.
This commit is contained in:
parent
ab1d245871
commit
c7605f21ae
2 changed files with 26 additions and 28 deletions
|
@ -133,7 +133,7 @@ affects what we see:
|
||||||
>>> del mydata
|
>>> del mydata
|
||||||
"""
|
"""
|
||||||
|
|
||||||
# Threading import is at end
|
from threading import currentThread, RLock, enumerate
|
||||||
|
|
||||||
class _localbase(object):
|
class _localbase(object):
|
||||||
__slots__ = '_local__key', '_local__args', '_local__lock'
|
__slots__ = '_local__key', '_local__args', '_local__lock'
|
||||||
|
@ -203,35 +203,30 @@ class local(_localbase):
|
||||||
lock.release()
|
lock.release()
|
||||||
|
|
||||||
|
|
||||||
def __del__():
|
# The default argument is a hack, to give __del__ a local name for
|
||||||
threading_enumerate = enumerate
|
# threading.enumerate (sidestepping problems with Python None'ing-out
|
||||||
__getattribute__ = object.__getattribute__
|
# module globals at shutdown time).
|
||||||
|
def __del__(self, _threading_enumerate=enumerate):
|
||||||
|
|
||||||
def __del__(self):
|
key = object.__getattribute__(self, '_local__key')
|
||||||
key = __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:
|
try:
|
||||||
threads = list(threading_enumerate())
|
__dict__ = thread.__dict__
|
||||||
except:
|
except AttributeError:
|
||||||
# if enumerate fails, as it seems to do during
|
# Thread is dying, rest in peace.
|
||||||
# shutdown, we'll skip cleanup under the assumption
|
continue
|
||||||
# that there is nothing to clean up
|
|
||||||
return
|
|
||||||
|
|
||||||
for thread in threads:
|
if key in __dict__:
|
||||||
try:
|
try:
|
||||||
__dict__ = thread.__dict__
|
del __dict__[key]
|
||||||
except AttributeError:
|
except KeyError:
|
||||||
# Thread is dying, rest in peace
|
pass # didn't have anything in this thread
|
||||||
continue
|
|
||||||
|
|
||||||
if key in __dict__:
|
|
||||||
try:
|
|
||||||
del __dict__[key]
|
|
||||||
except KeyError:
|
|
||||||
pass # didn't have anything in this thread
|
|
||||||
|
|
||||||
return __del__
|
|
||||||
__del__ = __del__()
|
|
||||||
|
|
||||||
from threading import currentThread, enumerate, RLock
|
|
||||||
|
|
|
@ -72,6 +72,9 @@ Extension Modules
|
||||||
Library
|
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 #790710: Add breakpoint command lists in pdb.
|
||||||
|
|
||||||
- Patch #1063914: Add Tkinter.Misc.clipboard_get().
|
- Patch #1063914: Add Tkinter.Misc.clipboard_get().
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue