Skip to content

Commit 9f0604c

Browse files
committed
Don't import the name from multiprocessing directly to avoid confusion.
1 parent 2b25f54 commit 9f0604c

File tree

1 file changed

+11
-7
lines changed

1 file changed

+11
-7
lines changed

Lib/test/test_concurrent_futures.py

Lines changed: 11 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -26,10 +26,10 @@
2626
PENDING, RUNNING, CANCELLED, CANCELLED_AND_NOTIFIED, FINISHED, Future,
2727
BrokenExecutor)
2828
from concurrent.futures.process import BrokenProcessPool, _check_system_limits
29-
from multiprocessing import get_context
3029

3130
import multiprocessing.process
3231
import multiprocessing.util
32+
import multiprocessing as mp
3333

3434

3535
if support.check_sanitizer(address=True, memory=True):
@@ -143,7 +143,7 @@ def tearDown(self):
143143
super().tearDown()
144144

145145
def get_context(self):
146-
return get_context(self.ctx)
146+
return mp.get_context(self.ctx)
147147

148148

149149
class ThreadPoolMixin(ExecutorMixin):
@@ -922,7 +922,7 @@ def submit(pool):
922922
pool.submit(submit, pool)
923923

924924
for _ in range(50):
925-
with futures.ProcessPoolExecutor(1, mp_context=get_context('fork')) as workers:
925+
with futures.ProcessPoolExecutor(1, mp_context=mp.get_context('fork')) as workers:
926926
workers.submit(tuple)
927927

928928

@@ -992,7 +992,7 @@ def test_traceback(self):
992992
def test_ressources_gced_in_workers(self):
993993
# Ensure that argument for a job are correctly gc-ed after the job
994994
# is finished
995-
mgr = get_context(self.ctx).Manager()
995+
mgr = self.get_context().Manager()
996996
obj = EventfulGCObj(mgr)
997997
future = self.executor.submit(id, obj)
998998
future.result()
@@ -1039,6 +1039,8 @@ def test_idle_process_reuse_multiple(self):
10391039
executor.shutdown()
10401040

10411041
def test_max_tasks_per_child(self):
1042+
# not using self.executor as we need to control construction.
1043+
# arguably this could go in another class w/o that mixin.
10421044
executor = self.executor_type(
10431045
1, mp_context=self.get_context(), max_tasks_per_child=3)
10441046
f1 = executor.submit(os.getpid)
@@ -1060,6 +1062,8 @@ def test_max_tasks_per_child(self):
10601062
executor.shutdown()
10611063

10621064
def test_max_tasks_early_shutdown(self):
1065+
# not using self.executor as we need to control construction.
1066+
# arguably this could go in another class w/o that mixin.
10631067
executor = self.executor_type(
10641068
3, mp_context=self.get_context(), max_tasks_per_child=1)
10651069
futures = []
@@ -1171,7 +1175,7 @@ def _check_crash(self, error, func, *args, ignore_stderr=False):
11711175
self.executor.shutdown(wait=True)
11721176

11731177
executor = self.executor_type(
1174-
max_workers=2, mp_context=get_context(self.ctx))
1178+
max_workers=2, mp_context=self.get_context())
11751179
res = executor.submit(func, *args)
11761180

11771181
if ignore_stderr:
@@ -1250,7 +1254,7 @@ def test_shutdown_deadlock(self):
12501254
# if a worker fails after the shutdown call.
12511255
self.executor.shutdown(wait=True)
12521256
with self.executor_type(max_workers=2,
1253-
mp_context=get_context(self.ctx)) as executor:
1257+
mp_context=self.get_context()) as executor:
12541258
self.executor = executor # Allow clean up in fail_on_deadlock
12551259
f = executor.submit(_crash, delay=.1)
12561260
executor.shutdown(wait=True)
@@ -1263,7 +1267,7 @@ def test_shutdown_deadlock_pickle(self):
12631267
# Reported in bpo-39104.
12641268
self.executor.shutdown(wait=True)
12651269
with self.executor_type(max_workers=2,
1266-
mp_context=get_context(self.ctx)) as executor:
1270+
mp_context=self.get_context()) as executor:
12671271
self.executor = executor # Allow clean up in fail_on_deadlock
12681272

12691273
# Start the executor and get the executor_manager_thread to collect

0 commit comments

Comments
 (0)