Uh oh!
There was an error while loading.Please reload this page.
- Notifications
You must be signed in to change notification settings - Fork32.1k
gh-109595: Add -Xcpu_count=<n> cmdline for container users#109667
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to ourterms of service andprivacy statement. We’ll occasionally send you account related emails.
Already on GitHub?Sign in to your account
Uh oh!
There was an error while loading.Please reload this page.
Conversation
corona10 commentedSep 21, 2023 • edited
Loading Uh oh!
There was an error while loading.Please reload this page.
edited
Uh oh!
There was an error while loading.Please reload this page.
Please read the issue of why this flag is needed and see also actual use-case from#109595 (comment) Even if the container system is important these days, there is no way to limit CPU resources for the container environment from Python program side. |
Uh oh!
There was an error while loading.Please reload this page.
Uh oh!
There was an error while loading.Please reload this page.
Uh oh!
There was an error while loading.Please reload this page.
Uh oh!
There was an error while loading.Please reload this page.
Uh oh!
There was an error while loading.Please reload this page.
Uh oh!
There was an error while loading.Please reload this page.
Uh oh!
There was an error while loading.Please reload this page.
Uh oh!
There was an error while loading.Please reload this page.
Uh oh!
There was an error while loading.Please reload this page.
Uh oh!
There was an error while loading.Please reload this page.
Co-authored-by: Victor Stinner <vstinner@python.org>
Co-authored-by: Victor Stinner <vstinner@python.org>
Programs/_testembed.c Outdated
@@ -715,6 +715,7 @@ static int test_init_from_config(void) | |||
putenv("PYTHONINTMAXSTRDIGITS=6666"); | |||
config.int_max_str_digits = 31337; | |||
config.cpu_count = -1; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others.Learn more.
Can you please set a more interesting value like 1234?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others.Learn more.
Can you please document the change in Doc/whatsnew/3.13.rst?
Doc/using/cmdline.rst Outdated
* :samp:`-X cpu_count={n}` will override the number of CPU count from system. | ||
If this option is provided, :func:`os.cpu_count` will return the overrided value. | ||
And *n* must be greater equal then 1. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others.Learn more.
*:samp:`-X cpu_count={n}`will overridethe number of CPU count from system. | |
If this option is provided,:func:`os.cpu_count`will return the overridedvalue. | |
And *n* must be greaterequalthen 1. | |
*:samp:`-X cpu_count={n}`overridesthe number of CPU count from system: | |
:func:`os.cpu_count`returns *n*. Thevalue *n* must be greater than | |
orequalto 1. |
Uh oh!
There was an error while loading.Please reload this page.
Misc/NEWS.d/next/Core and Builtins/2023-09-22-01-44-53.gh-issue-109595.fVINgD.rst OutdatedShow resolvedHide resolved
Uh oh!
There was an error while loading.Please reload this page.
Uh oh!
There was an error while loading.Please reload this page.
Python/initconfig.c Outdated
static PyStatus | ||
config_init_cpu_count(PyConfig *config) | ||
{ | ||
int cpu_count = -1; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others.Learn more.
You can move the variable declaration inside the "if (sep)" block. Does ithave to be initialized?
If you are afraid of undefined behavior, maybe config_wstr_to_int() should set*result
to 0 on error.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others.Learn more.
Now I addedPYTHONCPUCOUNT
envvar, so the current structure will be needed.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others.Learn more.
If you want, youcan move the variable declaration inside each "if (env)" block and duplicate the variable, to better show its scope. But well, that's just a personal preference. Feel free to ignore my coding style remark ;-)
Uh oh!
There was an error while loading.Please reload this page.
Co-authored-by: Victor Stinner <vstinner@python.org>
Co-authored-by: Victor Stinner <vstinner@python.org>
Uh oh!
There was an error while loading.Please reload this page.
I'm fine with os._get_cpu_count_config() returning a string. For the env var, apparently, using an underscore or not became a hot debate: seehttps://discuss.python.org/t/change-environment-variable-style/35180 discussion. Maybe we should wait a few days until the dust settle down to see if a consensus is reached? Python 3.13.0 alpha 1 isscheduled for Tuesday, 2023-10-17, we will have time. Also, it may wait for alpha 2 ;-) |
Uh oh!
There was an error while loading.Please reload this page.
Uh oh!
There was an error while loading.Please reload this page.
Uh oh!
There was an error while loading.Please reload this page.
Adds PYTHON_CPU_COUNT help text.Mentions multiprocessing.cpu_count.rewords a few statements.
The majority wants PYTHON_CPU_COUNT env name:https://discuss.python.org/t/change-environment-variable-style/35180 |
corona10 commentedOct 9, 2023 • edited
Loading Uh oh!
There was an error while loading.Please reload this page.
edited
Uh oh!
There was an error while loading.Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others.Learn more.
LGTM. I see that you addressed the two@gpshead's comments. You can merge.
Congrats. |
🎉 thanks everybody! |
Follow-up: issue#110649 to add -X cpu_count=process. |
…hon#109667)---------Co-authored-by: Victor Stinner <vstinner@python.org>Co-authored-by: Gregory P. Smith [Google LLC] <greg@krypto.org>
Uh oh!
There was an error while loading.Please reload this page.
📚 Documentation preview 📚:https://cpython-previews--109667.org.readthedocs.build/