Skip to content

Commit b288fe3

Browse files
committed
Fix maximum number of ProcessPool workers (#7385)
Set the default for the maximum number of workers to `None` which lets the executor decide. Practically that makes it equal to the number of cores or the internal limit (whichever is lower). That's lower than our 1.5 * cores (which I imagine is to leave room for a bit of IO) but at least will never hit the limit. The other usage of ProcessPoolExecutor (in Dependencies.py) always takes a number rather than guessing a default, so should be safe. Fixes #7384
1 parent 2a8ee41 commit b288fe3

2 files changed

Lines changed: 7 additions & 9 deletions

File tree

Cython/Build/Cythonize.py

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -12,10 +12,8 @@
1212

1313
try:
1414
import multiprocessing
15-
parallel_compiles = int(multiprocessing.cpu_count() * 1.5)
1615
except ImportError:
1716
multiprocessing = None
18-
parallel_compiles = 0
1917

2018

2119
def find_package_base(path):
@@ -85,7 +83,8 @@ def _build(ext_modules, parallel):
8583
if not modcount:
8684
return
8785

88-
serial_execution_mode = modcount == 1 or parallel < 2
86+
serial_execution_mode = modcount == 1 or (
87+
parallel is not None and parallel < 2)
8988

9089
try:
9190
pool_cm = (
@@ -248,8 +247,8 @@ def create_args_parser():
248247
help="use CODESTRING as pre-benchmark setup code for --bench")
249248

250249
parser.add_argument('-j', '--parallel', dest='parallel', metavar='N',
251-
type=int, default=parallel_compiles,
252-
help=f'run builds in N parallel jobs (default: {parallel_compiles or 1})')
250+
type=int, default=None,
251+
help='run builds in N parallel jobs (default: CPU count)')
253252
parser.add_argument('-f', '--force', dest='force', action='store_true', default=None,
254253
help='force recompilation')
255254
parser.add_argument('-q', '--quiet', dest='quiet', action='store_true', default=None,

Cython/Build/Tests/TestCythonizeArgsParser.py

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
from Cython.Build.Cythonize import (
22
create_args_parser, parse_args_raw, parse_args,
3-
parallel_compiles
43
)
54

65
from Cython.Compiler import Options
@@ -22,7 +21,9 @@ def setUp(self):
2221
def are_default(self, options, skip):
2322
# empty containers
2423
empty_containers = ['directives', 'compile_time_env', 'options', 'excludes']
25-
are_none = ['language_level', 'annotate', 'build', 'build_inplace', 'force', 'quiet', 'lenient', 'keep_going', 'no_docstrings']
24+
are_none = [
25+
'language_level', 'annotate', 'build', 'build_inplace', 'force', 'quiet', 'lenient', 'keep_going', 'no_docstrings', 'parallel'
26+
]
2627
for opt_name in empty_containers:
2728
if len(getattr(options, opt_name))!=0 and (opt_name not in skip):
2829
self.assertEqual(opt_name,"", msg="For option "+opt_name)
@@ -31,8 +32,6 @@ def are_default(self, options, skip):
3132
if (getattr(options, opt_name) is not None) and (opt_name not in skip):
3233
self.assertEqual(opt_name,"", msg="For option "+opt_name)
3334
return False
34-
if options.parallel!=parallel_compiles and ('parallel' not in skip):
35-
return False
3635
return True
3736

3837
# testing directives:

0 commit comments

Comments
 (0)