summaryrefslogtreecommitdiffstats
path: root/Lib/test/test_threading.py
diff options
context:
space:
mode:
authorJeffrey Yasskin <jyasskin@gmail.com>2008-02-23 20:40:35 (GMT)
committerJeffrey Yasskin <jyasskin@gmail.com>2008-02-23 20:40:35 (GMT)
commita885c1521a547d728e04bbede8c669417d41b9bb (patch)
tree6ec3939f235ea546701f5d3dafaf0ce1e78f815e /Lib/test/test_threading.py
parent3414ea9ed9fce2b9ce74e8b6c7c3b4278b526685 (diff)
downloadcpython-a885c1521a547d728e04bbede8c669417d41b9bb.zip
cpython-a885c1521a547d728e04bbede8c669417d41b9bb.tar.gz
cpython-a885c1521a547d728e04bbede8c669417d41b9bb.tar.bz2
Followup to r61011: Also avoid the reference cycle when the Thread's target
raises an exception.
Diffstat (limited to 'Lib/test/test_threading.py')
-rw-r--r--Lib/test/test_threading.py14
1 files changed, 11 insertions, 3 deletions
diff --git a/Lib/test/test_threading.py b/Lib/test/test_threading.py
index 91f5a8b..dc94603 100644
--- a/Lib/test/test_threading.py
+++ b/Lib/test/test_threading.py
@@ -256,23 +256,31 @@ class ThreadTests(unittest.TestCase):
def test_no_refcycle_through_target(self):
class RunSelfFunction(object):
- def __init__(self):
+ def __init__(self, should_raise):
# The links in this refcycle from Thread back to self
# should be cleaned up when the thread completes.
+ self.should_raise = should_raise
self.thread = threading.Thread(target=self._run,
args=(self,),
kwargs={'yet_another':self})
self.thread.start()
def _run(self, other_ref, yet_another):
- pass
+ if self.should_raise:
+ raise SystemExit
- cyclic_object = RunSelfFunction()
+ cyclic_object = RunSelfFunction(should_raise=False)
weak_cyclic_object = weakref.ref(cyclic_object)
cyclic_object.thread.join()
del cyclic_object
self.assertEquals(None, weak_cyclic_object())
+ raising_cyclic_object = RunSelfFunction(should_raise=True)
+ weak_raising_cyclic_object = weakref.ref(raising_cyclic_object)
+ raising_cyclic_object.thread.join()
+ del raising_cyclic_object
+ self.assertEquals(None, weak_raising_cyclic_object())
+
class ThreadingExceptionTests(unittest.TestCase):
# A RuntimeError should be raised if Thread.start() is called