Skip to content

Commit 1676673

Browse files
committed
Fix EM_PYTHON_MULTIPROCESSING under windows
This mirrors the upstream bugfix in python 3.8.0 which limits the size of the worker pool to 61: python/cpython#13132 Fixes: #13785
1 parent 9227a01 commit 1676673

File tree

1 file changed

+9
-3
lines changed

1 file changed

+9
-3
lines changed

tools/shared.py

+9-3
Original file line numberDiff line numberDiff line change
@@ -152,13 +152,19 @@ def run_multiple_processes(commands,
152152
cwd=None):
153153
if env is None:
154154
env = os.environ.copy()
155-
# By default, avoid using Python multiprocessing library due to a large amount of bugs it has on Windows (#8013, #718, #13785, etc.)
156-
# Use EM_PYTHON_MULTIPROCESSING=1 environment variable to enable it. It can be faster, but may not work on Windows.
155+
# By default, avoid using Python multiprocessing library due to a large amount
156+
# of bugs it has on Windows (#8013, #718, etc.)
157+
# Use EM_PYTHON_MULTIPROCESSING=1 environment variable to enable it. It can be
158+
# faster, but may not work on Windows.
157159
if int(os.getenv('EM_PYTHON_MULTIPROCESSING', '0')):
158160
import multiprocessing
161+
max_workers = get_num_cores()
159162
global multiprocessing_pool
160163
if not multiprocessing_pool:
161-
multiprocessing_pool = multiprocessing.Pool(processes=get_num_cores())
164+
if WINDOWS:
165+
# Fix for python < 3.8 on windows. See: https://github.com/python/cpython/pull/13132
166+
max_workers = min(max_workers, 61)
167+
multiprocessing_pool = multiprocessing.Pool(processes=max_workers)
162168
return multiprocessing_pool.map(mp_run_process, [(cmd, env, route_stdout_to_temp_files_suffix, pipe_stdout, check, cwd) for cmd in commands], chunksize=1)
163169

164170
std_outs = []

0 commit comments

Comments
 (0)