mirror of
https://github.com/python/cpython.git
synced 2025-07-29 14:15:07 +00:00
Prevent classes like:
class RunSelfFunction(object): def __init__(self): self.thread = threading.Thread(target=self._run) self.thread.start() def _run(self): pass from creating a permanent cycle between the object and the thread by having the Thread delete its references to the object when it completes. As an example of the effect of this bug, paramiko.Transport inherits from Thread to avoid it.
This commit is contained in:
parent
1beea27299
commit
3414ea9ed9
2 changed files with 23 additions and 0 deletions
|
@ -444,6 +444,9 @@ class Thread(_Verbose):
|
|||
def run(self):
|
||||
if self.__target:
|
||||
self.__target(*self.__args, **self.__kwargs)
|
||||
# Avoid a refcycle if the thread is running a function with an
|
||||
# argument that has a member that points to the thread.
|
||||
del self.__target, self.__args, self.__kwargs
|
||||
|
||||
def __bootstrap(self):
|
||||
# Wrapper around the real bootstrap code that ignores
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue