summaryrefslogtreecommitdiffstats
path: root/Lib/test/test_concurrent_futures.py
diff options
context:
space:
mode:
authorAntoine Pitrou <solipsis@pitrou.net>2012-03-31 18:23:30 (GMT)
committerAntoine Pitrou <solipsis@pitrou.net>2012-03-31 18:23:30 (GMT)
commitf70401e842d120407c5450d0b89cece8616af8e4 (patch)
tree28d58598132a50abf42600af358a764de5246568 /Lib/test/test_concurrent_futures.py
parent317075de2981c9283e7af7bcf727ef8ae8ee4f4e (diff)
downloadcpython-f70401e842d120407c5450d0b89cece8616af8e4.zip
cpython-f70401e842d120407c5450d0b89cece8616af8e4.tar.gz
cpython-f70401e842d120407c5450d0b89cece8616af8e4.tar.bz2
Issue #14406: Fix a race condition when using `concurrent.futures.wait(return_when=ALL_COMPLETED)`.
Patch by Matt Joiner.
Diffstat (limited to 'Lib/test/test_concurrent_futures.py')
-rw-r--r--Lib/test/test_concurrent_futures.py18
1 files changed, 17 insertions, 1 deletions
diff --git a/Lib/test/test_concurrent_futures.py b/Lib/test/test_concurrent_futures.py
index 372da27..2afa938 100644
--- a/Lib/test/test_concurrent_futures.py
+++ b/Lib/test/test_concurrent_futures.py
@@ -183,7 +183,9 @@ class ProcessPoolShutdownTest(ProcessPoolMixin, ExecutorShutdownTest):
for p in processes:
p.join()
+
class WaitTests(unittest.TestCase):
+
def test_first_completed(self):
future1 = self.executor.submit(mul, 21, 2)
future2 = self.executor.submit(time.sleep, 1.5)
@@ -284,7 +286,21 @@ class WaitTests(unittest.TestCase):
class ThreadPoolWaitTests(ThreadPoolMixin, WaitTests):
- pass
+
+ def test_pending_calls_race(self):
+ # Issue #14406: multi-threaded race condition when waiting on all
+ # futures.
+ event = threading.Event()
+ def future_func():
+ event.wait()
+ oldswitchinterval = sys.getswitchinterval()
+ sys.setswitchinterval(1e-6)
+ try:
+ fs = {self.executor.submit(future_func) for i in range(100)}
+ event.set()
+ futures.wait(fs, return_when=futures.ALL_COMPLETED)
+ finally:
+ sys.setswitchinterval(oldswitchinterval)
class ProcessPoolWaitTests(ProcessPoolMixin, WaitTests):