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-99113: A Per-Interpreter GIL!#99114

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

Conversation

ericsnowcurrently
Copy link
Member

@ericsnowcurrentlyericsnowcurrently commentedNov 5, 2022
edited
Loading

I've split up this PR:

That last one is effectively the superseder of this one.



This is the culmination of PEP 684 (and of my 8-year long multi-core Python project)!

Each subinterpreter may now be created with its own GIL (viaPy_NewInterpreterFromConfig()). If not so configured then the interpreter will share with the main interpreter--the status quo since the subinterpreters were added decades ago. The main interpreter always has its own GIL and subinterpreters fromPy_NewInterpreter() will always share with the main interpreter.


This is essentially the correct implementation but it may change here and there before we've reached the end.

We won't merge this until:

  • PEP 684 is accepted (if itis accepted), which might be up to a few months due to the changing steering council
  • interpreters have been sufficiently isolated (seemy checklist)
  • we have been extra careful about testing this

I'm merging in other branches that this one relies on, but those will wash out as the other PRs get merged. In the meantime, you can see the actual changes here:https://github.com/python/cpython/compare/main...ericsnowcurrently:per-interpreter-gil-new-bare?expand=1.

hannes and Mytherin reacted with thumbs up emojiiritkatriel, Fidget-Spinner, corona10, dgiger42, bgruening, a-reich, erlend-aasland, ivoflipse, barneygale, gpshead, and 15 more reacted with hooray emoji
@gvanrossum
Copy link
Member

318 commits, 114 files, 23 reviewers… How are we going to do this?

TitaniumHocker and zacqed reacted with eyes emoji

@arhadthedev
Copy link
Member

arhadthedev commentedMay 5, 2023
edited
Loading

318 commits, 114 files, 23 reviewers…

We can create a separate PR that just defines a no-op slotPy_mod_multiple_interpreters/Py_MOD_* and adds{Py_mod_multiple_interpreters, Py_MOD_PER_INTERPRETER_GIL_SUPPORTED} to the modules.

Thanks to it, this PR will become a much smaller follow-up.

@AlexWaygood
Copy link
Member

@AlexWaygood AlexWaygood removed request forhttps://github.com/orgs/python/teams/windows-team,corona10,pablogsal,erlend-aasland,Fidget-Spinner,isidentical,kumaraditya303 andAlexWaygood

Not sure how that happened — I only meant to remove my own request for review...

@erlend-aasland
Copy link
Contributor

318 commits, 114 files, 23 reviewers… How are we going to do this?

Actually, most of the changed files are repetitive, trivial updates of various extension module's PyModuleDef structs.

@arhadthedev
Copy link
Member

most of the changed files are repetitive, trivial updates of various extension module's PyModuleDef structs

Their repetitiveness takes attention from other parts of the diff and requires to constantly scroll through all of them for each inter-file comparison in other parts of the PR. It makes the analysis harder. That's why I proposed to move them out into a separate PR, merge it and update this PR.

@zooba
Copy link
Member

zooba commentedMay 5, 2023
edited
Loading

I quickly went through and marked all those files as "Viewed", then used the File Filter drop down to hide viewed files. So I've only got 7 files left with non-trivial changes, one of which is the NEWS entry.

image

Looks like the "viewed" state is remembered, but the filter needs to be set each time I go back in.

arhadthedev and erlend-aasland reacted with thumbs up emoji

const PyInterpreterConfig config = _PyInterpreterConfig_LEGACY_INIT;
PyInterpreterConfig config = _PyInterpreterConfig_LEGACY_INIT;
// The main interpreter always has its own GIL.
config.own_gil = 1;
Copy link
Member

Choose a reason for hiding this comment

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

Presumably we're in a lot of trouble if the main interpreter exits first...

Do we have mechanisms to ensure it outlives any subinterpreters that share its GIL? Or perhaps we should reference count the GIL instead of marking ownership?

Copy link
MemberAuthor

Choose a reason for hiding this comment

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

Yeah, the main interpreter must be the last one. There are many things that break if that isn't the case.

struct _gil_runtime_state *gil = &_PyRuntime.ceval.gil;
PyInterpreterState *interp = _PyInterpreterState_Get();
struct _gil_runtime_state *gil = interp->ceval.gil;
assert(gil != NULL);
gil->interval = microseconds;
Copy link
Member

Choose a reason for hiding this comment

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

Do we need some way to propagate this to new subinterpreters? I don't see it if it's here.

Not sure whether this would catch people out or not. Presumably increasing the switch count is less important with proper parallelism, and it's documented as setting "the interpreter's switch interval" so we're clear on that front. But it may be surprising.

Probably only worth adding a note to the sys docs to clarify that it doesn't propagate to new subinterpreter GILs.

Copy link
MemberAuthor

Choose a reason for hiding this comment

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

Yeah, we'll make sure the docs are clear.

Copy link
MemberAuthor

Choose a reason for hiding this comment

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

I've left a TODO note on the issue:#99113 (comment).

@ericsnowcurrently
Copy link
MemberAuthor

I had seriously considered splitting this PR up yesterday. I should have listened to myself. 🙂 I'm going to split it up.

zooba and erlend-aasland reacted with thumbs up emoji

@ericsnowcurrently
Copy link
MemberAuthor

I've noted the new PRs above in the PR summary.

ericsnowcurrently added a commit that referenced this pull requestMay 5, 2023
…04148)I'll be adding a value to indicate support for per-interpreter GIL ingh-99114.
jbower-fb pushed a commit to jbower-fb/cpython that referenced this pull requestMay 8, 2023
Sign up for freeto join this conversation on GitHub. Already have an account?Sign in to comment
Reviewers

@zoobazoobazooba left review comments

@arhadthedevarhadthedevarhadthedev left review comments

@gvanrossumgvanrossumAwaiting requested review from gvanrossum

@JelleZijlstraJelleZijlstraAwaiting requested review from JelleZijlstraJelleZijlstra is a code owner

@rhettingerrhettingerAwaiting requested review from rhettingerrhettinger is a code owner

@gpsheadgpsheadAwaiting requested review from gpsheadgpshead is a code owner

@berkerpeksagberkerpeksagAwaiting requested review from berkerpeksagberkerpeksag is a code owner

@pgansslepganssleAwaiting requested review from pgansslepganssle is a code owner

@abalkinabalkinAwaiting requested review from abalkinabalkin is a code owner

@brettcannonbrettcannonAwaiting requested review from brettcannonbrettcannon is a code owner

@encukouencukouAwaiting requested review from encukou

@ncoghlanncoghlanAwaiting requested review from ncoghlanncoghlan is a code owner

@warsawwarsawAwaiting requested review from warsawwarsaw is a code owner

@tirantiranAwaiting requested review from tirantiran is a code owner

@1st11st1Awaiting requested review from 1st11st1 is a code owner

@asvetlovasvetlovAwaiting requested review from asvetlovasvetlov is a code owner

@willingcwillingcAwaiting requested review from willingcwillingc is a code owner

Assignees
No one assigned
Projects
None yet
Milestone
No milestone
Development

Successfully merging this pull request may close these issues.

9 participants
@ericsnowcurrently@tonybaloney@gvanrossum@arhadthedev@AlexWaygood@erlend-aasland@zooba@bedevere-bot@eduardo-elizondo

[8]ページ先頭

©2009-2025 Movatter.jp