diff options
author | Antoine Pitrou <solipsis@pitrou.net> | 2013-10-15 23:24:44 +0200 |
---|---|---|
committer | Antoine Pitrou <solipsis@pitrou.net> | 2013-10-15 23:24:44 +0200 |
commit | 23ceb1c6ff78eafe9b9eee49910af1d989f2cba6 (patch) | |
tree | b4a100cc05a5097c02449f36657fe255380af30b /Lib/test/test_concurrent_futures.py | |
parent | 5bdfec59c17658e8e9c76d5626b82e5444ca0587 (diff) | |
parent | 85e4a3e5a491c473eecfbc96a7451ebad72e5191 (diff) | |
download | cpython-23ceb1c6ff78eafe9b9eee49910af1d989f2cba6.tar.gz |
Issue #14407: Fix unittest test discovery in test_concurrent_futures.
Diffstat (limited to 'Lib/test/test_concurrent_futures.py')
-rw-r--r-- | Lib/test/test_concurrent_futures.py | 22 |
1 files changed, 22 insertions, 0 deletions
diff --git a/Lib/test/test_concurrent_futures.py b/Lib/test/test_concurrent_futures.py index 39230e1cf0..a7e945cb5e 100644 --- a/Lib/test/test_concurrent_futures.py +++ b/Lib/test/test_concurrent_futures.py @@ -15,6 +15,7 @@ import sys import threading import time import unittest +import weakref from concurrent import futures from concurrent.futures._base import ( @@ -52,6 +53,11 @@ def sleep_and_print(t, msg): sys.stdout.flush() +class MyObject(object): + def my_method(self): + pass + + class ExecutorMixin: worker_count = 5 @@ -396,6 +402,22 @@ class ExecutorTest: self.executor.map(str, [2] * (self.worker_count + 1)) self.executor.shutdown() + @test.support.cpython_only + def test_no_stale_references(self): + # Issue #16284: check that the executors don't unnecessarily hang onto + # references. + my_object = MyObject() + my_object_collected = threading.Event() + my_object_callback = weakref.ref( + my_object, lambda obj: my_object_collected.set()) + # Deliberately discarding the future. + self.executor.submit(my_object.my_method) + del my_object + + collected = my_object_collected.wait(timeout=5.0) + self.assertTrue(collected, + "Stale reference not collected within timeout.") + class ThreadPoolExecutorTest(ThreadPoolMixin, ExecutorTest, unittest.TestCase): def test_map_submits_without_iteration(self): |