Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
71 commits
Select commit Hold shift + click to select a range
41be170
gh-109595: Add -Xcpu_count=<n> cmdline for container users
corona10 Sep 21, 2023
f7a7428
Check style
corona10 Sep 21, 2023
7009bbe
Add help
corona10 Sep 21, 2023
d1f91d8
Apply suggestions from code review
corona10 Sep 21, 2023
8c92ed6
Apply suggestions from code review
corona10 Sep 21, 2023
c27bdfc
Check style
corona10 Sep 21, 2023
b13e5ee
Address code review
corona10 Sep 21, 2023
45fce16
Address code review
corona10 Sep 21, 2023
49a48e4
Address code review
corona10 Sep 21, 2023
829a8e8
Address code review
corona10 Sep 21, 2023
cfb33a4
Fix test
corona10 Sep 21, 2023
95a2173
Update NEWS.d
corona10 Sep 21, 2023
0394d1d
Address code review
corona10 Sep 21, 2023
f4a3f01
Update
corona10 Sep 21, 2023
60a28fe
Update
corona10 Sep 21, 2023
7e5595c
nit
corona10 Sep 21, 2023
8678012
Update
corona10 Sep 21, 2023
cbc5484
Add PYTHONCPUCOUNT
corona10 Sep 21, 2023
4622b60
Add PYTHONCPUCOUNT
corona10 Sep 21, 2023
50f0178
Apply suggestions from code review
corona10 Sep 21, 2023
5c3ac68
Update Python/initconfig.c
corona10 Sep 21, 2023
a276bfd
Fix
corona10 Sep 21, 2023
9c582be
Update whatsnew
corona10 Sep 21, 2023
35b952f
nit
corona10 Sep 21, 2023
f04ea58
Check style
corona10 Sep 21, 2023
7ecf705
Fix docs
corona10 Sep 21, 2023
18dcd44
Update doc
corona10 Sep 21, 2023
b344f4f
nit
corona10 Sep 21, 2023
8069d21
Update
corona10 Sep 21, 2023
c70bc82
Update
corona10 Sep 21, 2023
c8abc29
Update
corona10 Sep 21, 2023
2ac6901
Address code review
corona10 Sep 21, 2023
f0a3ebf
Address code review
corona10 Sep 21, 2023
89d8bb2
Address Victor's suggestion
corona10 Sep 24, 2023
66c617f
nit
corona10 Sep 24, 2023
4a72ed4
Address Erlend's review
corona10 Sep 26, 2023
0426e3e
fix
corona10 Sep 26, 2023
ac5329b
Merge remote-tracking branch 'upstream/main' into gh-109595
corona10 Sep 30, 2023
e50e678
fix
corona10 Sep 30, 2023
24fe0e4
Add space
corona10 Sep 30, 2023
32843ed
Update os.py
corona10 Sep 30, 2023
a954f1c
nit
corona10 Sep 30, 2023
3ab2bc4
Add test code
corona10 Sep 30, 2023
7231697
Update docs
corona10 Sep 30, 2023
b18da0d
fix
corona10 Oct 1, 2023
3579fc4
Address code reivew
corona10 Oct 1, 2023
134ed9e
Address code review
corona10 Oct 1, 2023
2bec7f4
Add test
corona10 Oct 1, 2023
9f7cb5e
fix
corona10 Oct 1, 2023
1217ab5
fix
corona10 Oct 1, 2023
64da2f9
fix
corona10 Oct 1, 2023
64c7329
fix
corona10 Oct 1, 2023
cc54afb
Update
corona10 Oct 1, 2023
ba421c7
Address code review
corona10 Oct 1, 2023
5f20bf6
Update NEWS.d
corona10 Oct 1, 2023
c11789b
Update
corona10 Oct 1, 2023
936c182
Update
corona10 Oct 1, 2023
2f0dc1c
Address code review
corona10 Oct 1, 2023
a7b2c88
Rename to PYTHON_CPU_COUNT
corona10 Oct 1, 2023
551c76d
Hidden overrided cpu count
corona10 Oct 2, 2023
75021be
Use overridden
corona10 Oct 2, 2023
57dd53b
Minor refactoring
corona10 Oct 2, 2023
3f9da50
Revert to PYTHONCPUCOUNT
corona10 Oct 2, 2023
57e82c5
fix
corona10 Oct 2, 2023
c37c8d0
Use PYTHON_CPU_COUNT
corona10 Oct 3, 2023
c7726e5
Address Greg's review
corona10 Oct 3, 2023
de8bf53
Address Greg's code review
corona10 Oct 3, 2023
633914b
nit
corona10 Oct 3, 2023
37fbdfe
Include multiprocessing in docs, reword.
gpshead Oct 3, 2023
a0cfb21
Merge remote-tracking branch 'upstream/main' into gh-109595
corona10 Oct 3, 2023
8daa3b7
Merge remote-tracking branch 'upstream/main' into gh-109595
corona10 Oct 7, 2023
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Include multiprocessing in docs, reword.
Adds PYTHON_CPU_COUNT help text.
Mentions multiprocessing.cpu_count.
rewords a few statements.
  • Loading branch information
gpshead committed Oct 3, 2023
commit 37fbdfe123db097c6d47fe8f2c1719c65e048893
6 changes: 3 additions & 3 deletions Doc/c-api/init_config.rst
Original file line number Diff line number Diff line change
Expand Up @@ -880,9 +880,9 @@ PyConfig

.. c:member:: int cpu_count

If the value of :c:member:`~PyConfig.cpu_count` is not ``-1`` then it will override
the return value of :func:`os.cpu_count` and :func:`os.process_cpu_count` functions
into *cpu_count*.
If the value of :c:member:`~PyConfig.cpu_count` is not ``-1`` then it will
override the return values of :func:`os.cpu_count`,
:func:`os.process_cpu_count`, and :func:`multiprocessing.cpu_count`.

Configured by the :samp:`-X cpu_count={n|default}` command line
flag or the :envvar:`PYTHON_CPU_COUNT` environment variable.
Expand Down
9 changes: 8 additions & 1 deletion Doc/library/multiprocessing.rst
Original file line number Diff line number Diff line change
Expand Up @@ -996,13 +996,20 @@ Miscellaneous

This number is not equivalent to the number of CPUs the current process can
use. The number of usable CPUs can be obtained with
``len(os.sched_getaffinity(0))``
:func:`os.process_cpu_count` (or ``len(os.sched_getaffinity(0))``).

When the number of CPUs cannot be determined a :exc:`NotImplementedError`
is raised.

.. seealso::
:func:`os.cpu_count`
:func:`os.process_cpu_count`

.. versionchanged:: 3.13

The return value can also be overridden using the
:option:`-X cpu_count <-X>` flag or :envvar:`PYTHON_CPU_COUNT` as this is
merely a wrapper around the :mod:`os` cpu count APIs.

.. function:: current_process()

Expand Down
13 changes: 7 additions & 6 deletions Doc/using/cmdline.rst
Original file line number Diff line number Diff line change
Expand Up @@ -546,11 +546,12 @@ Miscellaneous options
report Python calls. This option is only available on some platforms and
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 :func:`os.process_cpu_count`.
* :samp:`-X cpu_count={n}` overrides :func:`os.cpu_count`,
:func:`os.process_cpu_count`, and :func:`multiprocessing.cpu_count`.
*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:`PYTHON_CPU_COUNT`.
If *n* is ``default``, :func:`os.cpu_count` and :func:`os.process_cpu_count` are not overridden.
This option may be useful for users who need to limit CPU resources of a
container system. See also :envvar:`PYTHON_CPU_COUNT`.
If *n* is ``default``, nothing is overridden.

It also allows passing arbitrary values and retrieving them through the
:data:`sys._xoptions` dictionary.
Expand Down Expand Up @@ -1073,8 +1074,8 @@ conflict.

.. envvar:: PYTHON_CPU_COUNT

If this variable is set to a positive integer, it overrides
:func:`os.cpu_count` and and :func:`os.process_cpu_count` return result.
If this variable is set to a positive integer, it overrides the return
values of :func:`os.cpu_count` and :func:`os.process_cpu_count`.

See also the :option:`-X cpu_count <-X>` command-line option.

Expand Down
7 changes: 5 additions & 2 deletions Python/initconfig.c
Original file line number Diff line number Diff line change
Expand Up @@ -231,8 +231,9 @@ The following implementation-specific options are available:\n\
This helps avoid denial of service attacks when parsing untrusted data.\n\
The default is sys.int_info.default_max_str_digits. 0 disables.\n\
\n\
-X cpu_count=[n|default]: override CPU count of os.cpu_count() and os.process_cpu_count().\n\
This helps for users who need to limit CPU resources of a container system."
-X cpu_count=[n|default]: Override the return value of os.cpu_count(),\n\
os.process_cpu_count(), and multiprocessing.cpu_count(). This can help users who need\n\
to limit resources in a container."

#ifdef Py_STATS
"\n\
Expand Down Expand Up @@ -270,6 +271,8 @@ static const char usage_envvars[] =
" locale coercion and locale compatibility warnings on stderr.\n"
"PYTHONBREAKPOINT: if this variable is set to 0, it disables the default\n"
" debugger. It can be set to the callable of your debugger of choice.\n"
"PYTHON_CPU_COUNT: Overrides the return value of os.process_cpu_count(),\n"
" os.cpu_count(), and multiprocessing.cpu_count() if set to a positive integer.\n"
"PYTHONDEVMODE: enable the development mode.\n"
"PYTHONPYCACHEPREFIX: root directory for bytecode cache (pyc) files.\n"
"PYTHONWARNDEFAULTENCODING: enable opt-in EncodingWarning for 'encoding=None'.\n"
Expand Down