summaryrefslogtreecommitdiffstats
path: root/Lib/threading.py
diff options
context:
space:
mode:
Diffstat (limited to 'Lib/threading.py')
-rw-r--r--Lib/threading.py9
1 files changed, 7 insertions, 2 deletions
diff --git a/Lib/threading.py b/Lib/threading.py
index a20ff06..c09ec6a 100644
--- a/Lib/threading.py
+++ b/Lib/threading.py
@@ -441,8 +441,13 @@ class Thread(_Verbose):
_sleep(0.000001) # 1 usec, to let the thread run (Solaris hack)
def run(self):
- if self._target:
- self._target(*self._args, **self._kwargs)
+ try:
+ if self._target:
+ self._target(*self._args, **self._kwargs)
+ finally:
+ # 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