Skip to content

Commit

Permalink
Address code review
Browse files Browse the repository at this point in the history
  • Loading branch information
corona10 committed Oct 1, 2023
1 parent cc54afb commit ba421c7
Show file tree
Hide file tree
Showing 4 changed files with 13 additions and 13 deletions.
3 changes: 2 additions & 1 deletion Doc/c-api/init_config.rst
Original file line number Diff line number Diff line change
Expand Up @@ -881,7 +881,8 @@ 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` into <cpu_count>.
the return value of :func:`os.cpu_count` and :func:`os.process_cpu_count` functions
into *cpu_count*.
Configured by the :samp:`-X cpu_count={n|default}` command line
flag or the :envvar:`PYTHONCPUCOUNT` environment variable.
Expand Down
6 changes: 2 additions & 4 deletions Doc/using/cmdline.rst
Original file line number Diff line number Diff line change
Expand Up @@ -550,9 +550,7 @@ Miscellaneous options
*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`.
If *n* is ``default``, it follows default :func:`os.cpu_count` even if :envvar:`PYTHONCPUCOUNT`
is set.

If *n* is ``default``, :func:`os.cpu_count` and :func:`os.process_cpu_count` are not overridden.

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

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

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

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 @@ -173,7 +173,7 @@ os
* :func:`os.cpu_count` and :func:`os.process_cpu_count` can be overrided through
the new 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.
CPU resources of a container system without having to modify the container (application code).
(Contributed by Donghee Na in :gh:`109595`)

pathlib
Expand Down
15 changes: 8 additions & 7 deletions Lib/test/test_cmd_line.py
Original file line number Diff line number Diff line change
Expand Up @@ -879,24 +879,25 @@ def test_int_max_str_digits(self):
assert_python_failure('-c', code, PYTHONINTMAXSTRDIGITS='100')

res = assert_python_ok('-c', code)
res2int = self.res2int
current_max = sys.get_int_max_str_digits()
self.assertEqual(self.res2int(res), (current_max, current_max))
self.assertEqual(res2int(res), (current_max, current_max))
res = assert_python_ok('-X', 'int_max_str_digits=0', '-c', code)
self.assertEqual(self.res2int(res), (0, 0))
self.assertEqual(res2int(res), (0, 0))
res = assert_python_ok('-X', 'int_max_str_digits=4000', '-c', code)
self.assertEqual(self.res2int(res), (4000, 4000))
self.assertEqual(res2int(res), (4000, 4000))
res = assert_python_ok('-X', 'int_max_str_digits=100000', '-c', code)
self.assertEqual(self.res2int(res), (100000, 100000))
self.assertEqual(res2int(res), (100000, 100000))

res = assert_python_ok('-c', code, PYTHONINTMAXSTRDIGITS='0')
self.assertEqual(self.res2int(res), (0, 0))
self.assertEqual(res2int(res), (0, 0))
res = assert_python_ok('-c', code, PYTHONINTMAXSTRDIGITS='4000')
self.assertEqual(self.res2int(res), (4000, 4000))
self.assertEqual(res2int(res), (4000, 4000))
res = assert_python_ok(
'-X', 'int_max_str_digits=6000', '-c', code,
PYTHONINTMAXSTRDIGITS='4000'
)
self.assertEqual(self.res2int(res), (6000, 6000))
self.assertEqual(res2int(res), (6000, 6000))

def test_cpu_count(self):
code = "import os; print(os.cpu_count(), os.process_cpu_count())"
Expand Down

0 comments on commit ba421c7

Please sign in to comment.