Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 89d8bb2

Browse files
committed
Address Victor's suggestion
1 parent f0a3ebf commit 89d8bb2

File tree

3 files changed

+11
-0
lines changed

3 files changed

+11
-0
lines changed

Doc/using/cmdline.rst

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -550,6 +550,8 @@ Miscellaneous options
550550
*n* must be greater than or equal to 1.
551551
This option is useful for users who need to limit CPU resources of a container system.
552552
See also :envvar:`PYTHONCPUCOUNT`.
553+
If *n* is "default", it follows default :func:`os.cpu_count` even if :envvar:`PYTHONCPUCOUNT`
554+
is set.
553555

554556

555557
It also allows passing arbitrary values and retrieving them through the

Lib/test/test_cmd_line.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -906,6 +906,11 @@ def test_cpu_count(self):
906906
res = assert_python_ok('-X', 'cpu_count=4321', '-c', code)
907907
self.assertEqual(res.out.strip().decode("utf-8"), '4321')
908908

909+
def test_cpu_count_default(self):
910+
code = "import os; print(os.cpu_count())"
911+
res = assert_python_ok('-X', 'cpu_count=default', '-c', code)
912+
self.assertEqual(int(res.out.strip().decode("utf-8")), os.cpu_count())
913+
909914

910915
@unittest.skipIf(interpreter_requires_environment(),
911916
'Cannot run -I tests when PYTHON env vars are required.')

Python/initconfig.c

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1706,6 +1706,10 @@ config_init_cpu_count(PyConfig *config)
17061706
int cpu_count = -1;
17071707
const wchar_t *sep = wcschr(xoption, L'=');
17081708
if (sep) {
1709+
if (wcscmp(sep + 1, L"default") == 0) {
1710+
config->cpu_count = -1;
1711+
return _PyStatus_OK();
1712+
}
17091713
if (config_wstr_to_int(sep + 1, &cpu_count) < 0 || cpu_count < 1) {
17101714
goto error;
17111715
}

0 commit comments

Comments
 (0)