Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

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

Merged
corona10 merged 71 commits intopython:mainfromcorona10:gh-109595
Oct 10, 2023

Conversation

corona10
Copy link
Member

@corona10corona10 commentedSep 21, 2023
edited by github-actionsbot
Loading

item4, luzluna, black7375, Pribess, dalinaum, devunt, lohaswinner, and edmorley reacted with thumbs up emoji
@corona10
Copy link
MemberAuthor

cc@indygreg

@corona10
Copy link
MemberAuthor

corona10 commentedSep 21, 2023
edited
Loading

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.
JDK provides-XX:ActiveProcessorCount=<n> from JDK 21 instead of supporting cgroup, this patch will provide identical feature to Python user and super useful :)

@@ -715,6 +715,7 @@ static int test_init_from_config(void)

putenv("PYTHONINTMAXSTRDIGITS=6666");
config.int_max_str_digits = 31337;
config.cpu_count = -1;
Copy link
Member

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?

Copy link
Member

@vstinnervstinner left a 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?

Comment on lines 549 to 551
* :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.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others.Learn more.

Suggested change
*: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.

static PyStatus
config_init_cpu_count(PyConfig *config)
{
int cpu_count = -1;
Copy link
Member

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.

Copy link
MemberAuthor

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.

Copy link
Member

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 ;-)

corona10and others added3 commitsSeptember 22, 2023 03:13
Co-authored-by: Victor Stinner <vstinner@python.org>
Co-authored-by: Victor Stinner <vstinner@python.org>
@vstinner
Copy link
Member

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 ;-)

@corona10corona10 requested a review fromgpsheadOctober 3, 2023 02:12
@gpsheadgpshead added type-featureA feature request or enhancement docsDocumentation in the Doc dir 3.13bugs and security fixes labelsOct 3, 2023
@vstinner
Copy link
Member

The majority wants PYTHON_CPU_COUNT env name:https://discuss.python.org/t/change-environment-variable-style/35180

hugovk reacted with thumbs up emoji

@corona10
Copy link
MemberAuthor

corona10 commentedOct 9, 2023
edited
Loading

@gpshead I will merge this PR by tomorrow. Please let me know if there needs more change. :)
cc@vstinner

Copy link
Member

@vstinnervstinner left a 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.

@corona10corona10 merged commit0362cbf intopython:mainOct 10, 2023
@corona10corona10 deleted the gh-109595 branchOctober 10, 2023 10:00
@vstinner
Copy link
Member

Congrats.

@gpshead
Copy link
Member

🎉 thanks everybody!

vstinner and corona10 reacted with hooray emoji

@corona10
Copy link
MemberAuthor

Thanks@vstinner and@gpshead for all your efforts to consider every use case!!

@vstinner
Copy link
Member

Follow-up: issue#110649 to add -X cpu_count=process.

Glyphack pushed a commit to Glyphack/cpython that referenced this pull requestSep 2, 2024
…hon#109667)---------Co-authored-by: Victor Stinner <vstinner@python.org>Co-authored-by: Gregory P. Smith [Google LLC] <greg@krypto.org>
Sign up for freeto join this conversation on GitHub. Already have an account?Sign in to comment
Reviewers

@erlend-aaslanderlend-aaslanderlend-aasland left review comments

@vstinnervstinnervstinner approved these changes

@gpsheadgpsheadAwaiting requested review from gpsheadgpshead is a code owner

Assignees
No one assigned
Labels
3.13bugs and security fixesdocsDocumentation in the Doc dirtype-featureA feature request or enhancement
Projects
None yet
Milestone
No milestone
Development

Successfully merging this pull request may close these issues.

5 participants
@corona10@darjeeling@vstinner@gpshead@erlend-aasland

[8]ページ先頭

©2009-2025 Movatter.jp