Skip to content

Commit 827bbbb

Browse files
committed
Use multiprocessing.Manager for process based executors
1 parent 72783ce commit 827bbbb

File tree

2 files changed

+10
-3
lines changed

2 files changed

+10
-3
lines changed

Lib/test/test_concurrent_futures/test_wait.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -114,9 +114,9 @@ def test_all_completed(self):
114114

115115
def test_timeout(self):
116116
short_timeout = 0.050
117-
event = threading.Event()
117+
self.event.clear()
118118

119-
future = self.executor.submit(event.wait)
119+
future = self.executor.submit(self.event.wait)
120120

121121
finished, pending = futures.wait(
122122
[CANCELLED_AND_NOTIFIED_FUTURE,
@@ -126,7 +126,7 @@ def test_timeout(self):
126126
timeout=short_timeout,
127127
return_when=futures.ALL_COMPLETED)
128128

129-
event.set()
129+
self.event.set()
130130
futures.wait([future], return_when=futures.ALL_COMPLETED)
131131

132132
self.assertEqual(set([CANCELLED_AND_NOTIFIED_FUTURE,

Lib/test/test_concurrent_futures/util.py

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import multiprocessing
22
import sys
3+
import threading
34
import time
45
import unittest
56
from concurrent import futures
@@ -46,18 +47,24 @@ def setUp(self):
4647

4748
self.t1 = time.monotonic()
4849
if hasattr(self, "ctx"):
50+
self.manager = multiprocessing.Manager()
51+
self.event = self.manager.Event()
4952
self.executor = self.executor_type(
5053
max_workers=self.worker_count,
5154
mp_context=self.get_context(),
5255
**self.executor_kwargs)
5356
else:
57+
self.event = threading.Event()
5458
self.executor = self.executor_type(
5559
max_workers=self.worker_count,
5660
**self.executor_kwargs)
5761

5862
def tearDown(self):
5963
self.executor.shutdown(wait=True)
6064
self.executor = None
65+
if hasattr(self, "ctx"):
66+
self.manager.shutdown()
67+
self.manager = None
6168

6269
dt = time.monotonic() - self.t1
6370
if support.verbose:

0 commit comments

Comments
 (0)