summaryrefslogtreecommitdiff
path: root/Lib/test/test_threading.py
diff options
context:
space:
mode:
Diffstat (limited to 'Lib/test/test_threading.py')
-rw-r--r--Lib/test/test_threading.py20
1 files changed, 20 insertions, 0 deletions
diff --git a/Lib/test/test_threading.py b/Lib/test/test_threading.py
index 4f49d7f1cb..91f5a8b2df 100644
--- a/Lib/test/test_threading.py
+++ b/Lib/test/test_threading.py
@@ -8,6 +8,7 @@ import threading
import thread
import time
import unittest
+import weakref
# A trivial mutable counter.
class Counter(object):
@@ -253,6 +254,25 @@ class ThreadTests(unittest.TestCase):
finally:
sys.setcheckinterval(old_interval)
+ def test_no_refcycle_through_target(self):
+ class RunSelfFunction(object):
+ def __init__(self):
+ # The links in this refcycle from Thread back to self
+ # should be cleaned up when the thread completes.
+ self.thread = threading.Thread(target=self._run,
+ args=(self,),
+ kwargs={'yet_another':self})
+ self.thread.start()
+
+ def _run(self, other_ref, yet_another):
+ pass
+
+ cyclic_object = RunSelfFunction()
+ weak_cyclic_object = weakref.ref(cyclic_object)
+ cyclic_object.thread.join()
+ del cyclic_object
+ self.assertEquals(None, weak_cyclic_object())
+
class ThreadingExceptionTests(unittest.TestCase):
# A RuntimeError should be raised if Thread.start() is called