Skip to content

Commit

Permalink
Address code review
Browse files Browse the repository at this point in the history
  • Loading branch information
corona10 committed Sep 21, 2023
1 parent c8abc29 commit 2ac6901
Show file tree
Hide file tree
Showing 4 changed files with 5 additions and 3 deletions.
2 changes: 1 addition & 1 deletion Doc/using/cmdline.rst
Original file line number Diff line number Diff line change
Expand Up @@ -547,7 +547,7 @@ Miscellaneous options
will do nothing if is not supported on the current system. The default value
is "off". See also :envvar:`PYTHONPERFSUPPORT` and :ref:`perf_profiling`.
* :samp:`-X cpu_count={n}` overrides :func:`os.cpu_count`.
And *n* must be greater than 0.
*n* must be greater than or equal to 1.
This option is useful for users who need to limit CPU resources of a container system.
See also :envvar:`PYTHONCPUCOUNT`.

Expand Down
2 changes: 1 addition & 1 deletion Doc/whatsnew/3.13.rst
Original file line number Diff line number Diff line change
Expand Up @@ -167,7 +167,7 @@ os
--

* :func:`os.cpu_count` can be overrided through the new
environment variable :envvar:`PYTHONCPUCOUNT`, the new command-line option
environment variable :envvar:`PYTHONCPUCOUNT` or the new command-line option
:option:`-X cpu_count <-X>`. This option is useful for users who need to limit
CPU resources of a container system.(Contributed by Donghee Na in :gh:`109595`)

Expand Down
1 change: 1 addition & 0 deletions Modules/posixmodule.c
Original file line number Diff line number Diff line change
Expand Up @@ -14353,6 +14353,7 @@ os_cpu_count_impl(PyObject *module)
if (config->cpu_count > 0) {
return PyLong_FromLong(config->cpu_count);
}

int ncpu = 0;
#ifdef MS_WINDOWS
#ifdef MS_WINDOWS_DESKTOP
Expand Down
3 changes: 2 additions & 1 deletion Python/initconfig.c
Original file line number Diff line number Diff line change
Expand Up @@ -1690,9 +1690,9 @@ config_read_env_vars(PyConfig *config)
static PyStatus
config_init_cpu_count(PyConfig *config)
{
int cpu_count = -1;
const char *env = config_get_env(config, "PYTHONCPUCOUNT");
if (env) {
int cpu_count = -1;
if (_Py_str_to_int(env, &cpu_count) != 0) {
cpu_count = -1;
}
Expand All @@ -1702,6 +1702,7 @@ config_init_cpu_count(PyConfig *config)
}
const wchar_t *xoption = config_get_xoption(config, L"cpu_count");
if (xoption) {
int cpu_count = -1;
const wchar_t *sep = wcschr(xoption, L'=');
if (sep) {
if (config_wstr_to_int(sep + 1, &cpu_count) < 0 || cpu_count < 1) {
Expand Down

0 comments on commit 2ac6901

Please sign in to comment.