Skip to content

Commit 8494ac4

Browse files
authored
Fix EM_PYTHON_MULTIPROCESSING under windows (#17892)
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 967fce3 commit 8494ac4

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
@@ -165,13 +165,19 @@ def run_multiple_processes(commands,
165165
if env is None:
166166
env = os.environ.copy()
167167

168-
# By default, avoid using Python multiprocessing library due to a large amount of bugs it has on Windows (#8013, #718, #13785, etc.)
169-
# Use EM_PYTHON_MULTIPROCESSING=1 environment variable to enable it. It can be faster, but may not work on Windows.
168+
# By default, avoid using Python multiprocessing library due to a large amount
169+
# of bugs it has on Windows (#8013, #718, etc.)
170+
# Use EM_PYTHON_MULTIPROCESSING=1 environment variable to enable it. It can be
171+
# faster, but may not work on Windows.
170172
if int(os.getenv('EM_PYTHON_MULTIPROCESSING', '0')):
171173
import multiprocessing
174+
max_workers = get_num_cores()
172175
global multiprocessing_pool
173176
if not multiprocessing_pool:
174-
multiprocessing_pool = multiprocessing.Pool(processes=get_num_cores())
177+
if WINDOWS:
178+
# Fix for python < 3.8 on windows. See: https://github.com/python/cpython/pull/13132
179+
max_workers = min(max_workers, 61)
180+
multiprocessing_pool = multiprocessing.Pool(processes=max_workers)
175181
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)
176182

177183
std_outs = []

0 commit comments

Comments
 (0)