GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — gh-115999: Enable BINARY_SUBSCR_GETITEM for free-threaded build by corona10 · Pull Request #127737 · python/cpython

Conversation

@corona10

@corona10 corona10 commented Dec 8, 2024 •
edited by bedevere-app Bot
Loading

Uh oh!

There was an error while loading. Please reload this page.

Copy link
Copy Markdown
Member
  • Issue: Make the specializing interpreter thread-safe in --disable-gil builds #115999

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions
@corona10
pythongh-115999: Enable BINARY_SUBSCR_GETITEM for free-threaded build
bb23e4b
@corona10 corona10 added the DO-NOT-MERGE label Dec 8, 2024
@bedevere-app bedevere-app Bot mentioned this pull request Dec 8, 2024
Make the specializing interpreter thread-safe in --disable-gil builds #115999
Closed
corona10 added 2 commits December 8, 2024 18:59
@corona10
fix
b714963
@corona10
fix
9dd7103
@corona10 corona10 added the skip news label Dec 8, 2024
@corona10
fix
2953fb4
@corona10 corona10 changed the title [WIP] gh-115999: Enable BINARY_SUBSCR_GETITEM for free-threaded build gh-115999: Enable BINARY_SUBSCR_GETITEM for free-threaded build Dec 8, 2024
@corona10 corona10 removed the DO-NOT-MERGE label Dec 8, 2024
@corona10
corona10 marked this pull request as ready for review December 8, 2024 11:06
@corona10
corona10 requested a review from markshannon as a code owner December 8, 2024 11:06
@bedevere-app bedevere-app Bot added the awaiting core review label Dec 8, 2024
@corona10

corona10 commented Dec 8, 2024 •
edited
Loading

Uh oh!

There was an error while loading. Please reload this page.

Copy link
Copy Markdown
Member Author

@mpage, @colesbury

To enable BINARY_SUBSCR_GETITEM, we should handle TypeObject and _spec_cache which are mutable by other threads.
To handle this, I have introduced PyType_GetItemFromCache, _PyType_GetItemFromCacheWithVersion, and _PyType_CacheGetItemForSpecialization to lock the type and mutate them at the same transaction.

But I am not sure this approach is proper approach since I noticed that cached items can be mutated before the interpreter gets cached objects, so I have added the logic to check whether the item is NULL or FunctionObject, but please let me know if my approach is wrong.

Anyway, this is the first working version without error. PTAL.

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@corona10
corona10 requested review from colesbury and mpage December 8, 2024 11:06
corona10 added 2 commits December 8, 2024 20:09
@corona10
Fix for windows build
a059e68
@corona10
Revert "Fix for windows build"
d0a9f07
This reverts commit a059e68.
mpage
mpage reviewed Dec 10, 2024
View reviewed changes

@mpage mpage left a comment

Copy link
Copy Markdown
Contributor

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.

Thanks for working on this! I left a few comments inline.

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions
Comment thread Objects/typeobject.c Resolved

Uh oh!

There was an error while loading. Please reload this page.

Comment thread Objects/typeobject.c Resolved

Uh oh!

There was an error while loading. Please reload this page.

Comment thread Objects/typeobject.c Resolved

Uh oh!

There was an error while loading. Please reload this page.

Comment thread Objects/typeobject.c Resolved

Uh oh!

There was an error while loading. Please reload this page.

Comment thread Objects/typeobject.c Resolved

Uh oh!

There was an error while loading. Please reload this page.

Comment thread Python/bytecodes.c Outdated
PyTypeObject *tp = Py_TYPE(PyStackRef_AsPyObjectBorrow(container));
PyHeapTypeObject *ht = (PyHeapTypeObject *)tp;
PyObject *getitem = ht->_spec_cache.getitem;
PyObject *getitem = _PyType_GetItemFromCache(tp);

@mpage mpage Dec 10, 2024

Copy link
Copy Markdown
Contributor

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.

I think it's probably safe to reload getitem from the cache after the guard passes. (If the getitem in the cache is replaced after the guard passes, the new getitem cannot be mutated in a way that would change the function version: that would require stopping the world). However, I'd prefer that we pass the getitem that is loaded in _BINARY_SUBSCR_CHECK_FUNC to _BINARY_SUBSCR_INIT_CALL.

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions
Comment thread Python/specialize.c Resolved

Uh oh!

There was an error while loading. Please reload this page.

corona10 added 3 commits December 16, 2024 00:34
@corona10
Address partial review
55aa240
@corona10
fix
245d580
@corona10
fix
58c2289
@corona10 corona10 changed the title gh-115999: Enable BINARY_SUBSCR_GETITEM for free-threaded build [WIP] gh-115999: Enable BINARY_SUBSCR_GETITEM for free-threaded build Dec 15, 2024
corona10 added 3 commits December 16, 2024 23:21
@corona10
WIP
23d5d49
@corona10
fix
42ed55b
@corona10
fix
c555fcd
@corona10 corona10 changed the title [WIP] gh-115999: Enable BINARY_SUBSCR_GETITEM for free-threaded build gh-115999: Enable BINARY_SUBSCR_GETITEM for free-threaded build Dec 16, 2024
@corona10

corona10 commented Dec 16, 2024 •
edited
Loading

Uh oh!

There was an error while loading. Please reload this page.

Copy link
Copy Markdown
Member Author

@mpage Hmm would you like to take a look again?

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@corona10
fix
7b72e7b
@corona10
corona10 requested a review from mpage December 16, 2024 15:57
mpage
mpage reviewed Dec 16, 2024
View reviewed changes

@mpage mpage left a comment

Copy link
Copy Markdown
Contributor

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.

Overall approach is looking good! I'd still prefer it if we passed the getitem that is loaded in _BINARY_SUBSCR_CHECK_FUNC to _BINARY_SUBSCR_INIT_CALL. That would also allow us to avoid introducing the DEOPT_IF in _BINARY_SUBSCR_INIT_CALL. Is there a reason you don't want to do that?

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions
Comment thread Lib/test/test_opcache.py Resolved

Uh oh!

There was an error while loading. Please reload this page.

Comment thread Python/bytecodes.c Resolved

Uh oh!

There was an error while loading. Please reload this page.

@mpage

mpage commented Dec 18, 2024

Copy link
Copy Markdown
Contributor

I can't see it. You may forget to press the comment button, I guess :)

Oops - fixed!

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@corona10
Address code review
6ef74ac
@corona10
corona10 requested a review from mpage December 18, 2024 03:26
@corona10

corona10 commented Dec 18, 2024

Copy link
Copy Markdown
Member Author

Done :)

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

mpage
mpage reviewed Dec 18, 2024
View reviewed changes

@mpage mpage left a comment

Copy link
Copy Markdown
Contributor

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.

Looks good! I noticed one last thing then I think we're good to go.

We need to update the opcode definition of _BINARY_SUBSCR_INIT_CALL in Python/optimizer_bytecodes.c to handle the extra output (getitem) of _BINARY_SUBSCR_CHECK_FUNC.

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

corona10 reacted with thumbs up emoji
All reactions
  • 👍 1 reaction
@corona10
Address code review
47b80b4
@corona10
corona10 requested a review from Fidget-Spinner as a code owner December 18, 2024 18:46
@corona10
corona10 requested a review from mpage December 18, 2024 18:47
@corona10

corona10 commented Dec 18, 2024

Copy link
Copy Markdown
Member Author

Done! Even if I am not sure that this change is the correct for tier 2 because I have never handled this before :)

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@Fidget-Spinner

Fidget-Spinner commented Dec 18, 2024

Copy link
Copy Markdown
Member

The tier2 change is correct. I should add an automatic script that checks tier2 and tier1 definitions are synced so that you don't trip over this. Thanks Matt for catching that!

corona10 and mpage reacted with thumbs up emoji
All reactions
  • 👍 2 reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@corona10

corona10 commented Dec 18, 2024

Copy link
Copy Markdown
Member Author

@mpage Okay to merge this PR?

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@mpage

mpage commented Dec 19, 2024

Copy link
Copy Markdown
Contributor

I kicked off a couple of benchmark runs earlier today. They should be done shortly. Let’s wait for the results. Otherwise, looks great!

corona10 reacted with thumbs up emoji
All reactions
  • 👍 1 reaction

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

mpage
mpage approved these changes Dec 19, 2024
View reviewed changes

@mpage mpage left a comment

Copy link
Copy Markdown
Contributor

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.

Looks good! Benchmark results:

  • ~1% improvement on free-threaded builds
  • ~neutral on default builds

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions
@bedevere-app bedevere-app Bot added awaiting merge and removed awaiting core review labels Dec 19, 2024
@corona10
corona10 merged commit 48c70b8 into python:main Dec 19, 2024
@bedevere-app bedevere-app Bot removed the awaiting merge label Dec 19, 2024
@corona10
corona10 deleted the gh-115999-BINARY_SUBSCR-final branch December 19, 2024 02:08
@bedevere-bot

bedevere-bot commented Dec 19, 2024

Copy link
Copy Markdown

⚠️⚠️⚠️ Buildbot failure ⚠️⚠️⚠️

Hi! The buildbot PPC64LE Fedora Stable 3.x has failed when building commit 48c70b8.

What do you need to do:

  1. Don't panic.
  2. Check the buildbot page in the devguide if you don't know what the buildbots are or how they work.
  3. Go to the page of the buildbot that failed (https://buildbot.python.org/#/builders/90/builds/5364) and take a look at the build logs.
  4. Check if the failure is related to this commit (48c70b8) or if it is a false positive.
  5. If the failure is related to this commit, please, reflect that on the issue and make a new Pull Request with a fix.

You can take a look at the buildbot page here:

https://buildbot.python.org/#/builders/90/builds/5364

Failed tests:

  • test_socket

Failed subtests:

  • testStream - test.test_socket.ThreadedVSOCKSocketStreamTest.testStream

Summary of the results of the build (if available):

==

Click to see traceback logs
Traceback (most recent call last):
  File "/home/buildbot/buildarea/3.x.cstratak-fedora-stable-ppc64le/build/Lib/test/test_socket.py", line 550, in testStream
    msg = self.conn.recv(1024)
PermissionError: [Errno 13] Permission denied
All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@bedevere-bot

bedevere-bot commented Dec 19, 2024

Copy link
Copy Markdown

⚠️⚠️⚠️ Buildbot failure ⚠️⚠️⚠️

Hi! The buildbot PPC64LE Fedora Stable Clang 3.x has failed when building commit 48c70b8.

What do you need to do:

  1. Don't panic.
  2. Check the buildbot page in the devguide if you don't know what the buildbots are or how they work.
  3. Go to the page of the buildbot that failed (https://buildbot.python.org/#/builders/435/builds/5142) and take a look at the build logs.
  4. Check if the failure is related to this commit (48c70b8) or if it is a false positive.
  5. If the failure is related to this commit, please, reflect that on the issue and make a new Pull Request with a fix.

You can take a look at the buildbot page here:

https://buildbot.python.org/#/builders/435/builds/5142

Failed tests:

  • test_socket

Failed subtests:

  • testStream - test.test_socket.ThreadedVSOCKSocketStreamTest.testStream

Summary of the results of the build (if available):

==

Click to see traceback logs
Traceback (most recent call last):
  File "/home/buildbot/buildarea/3.x.cstratak-fedora-stable-ppc64le.clang/build/Lib/test/test_socket.py", line 550, in testStream
    msg = self.conn.recv(1024)
PermissionError: [Errno 13] Permission denied
All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@bedevere-bot

bedevere-bot commented Dec 19, 2024

Copy link
Copy Markdown

⚠️⚠️⚠️ Buildbot failure ⚠️⚠️⚠️

Hi! The buildbot PPC64LE Fedora Stable Clang Installed 3.x has failed when building commit 48c70b8.

What do you need to do:

  1. Don't panic.
  2. Check the buildbot page in the devguide if you don't know what the buildbots are or how they work.
  3. Go to the page of the buildbot that failed (https://buildbot.python.org/#/builders/451/builds/5124) and take a look at the build logs.
  4. Check if the failure is related to this commit (48c70b8) or if it is a false positive.
  5. If the failure is related to this commit, please, reflect that on the issue and make a new Pull Request with a fix.

You can take a look at the buildbot page here:

https://buildbot.python.org/#/builders/451/builds/5124

Failed tests:

  • test_socket

Failed subtests:

  • testStream - test.test_socket.ThreadedVSOCKSocketStreamTest.testStream

Summary of the results of the build (if available):

==

Click to see traceback logs
Traceback (most recent call last):
  File "/home/buildbot/buildarea/3.x.cstratak-fedora-stable-ppc64le.clang-installed/build/target/lib/python3.14/test/test_socket.py", line 550, in testStream
    msg = self.conn.recv(1024)
PermissionError: [Errno 13] Permission denied
All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@bedevere-bot

bedevere-bot commented Dec 19, 2024

Copy link
Copy Markdown

⚠️⚠️⚠️ Buildbot failure ⚠️⚠️⚠️

Hi! The buildbot PPC64LE Fedora Stable LTO + PGO 3.x has failed when building commit 48c70b8.

What do you need to do:

  1. Don't panic.
  2. Check the buildbot page in the devguide if you don't know what the buildbots are or how they work.
  3. Go to the page of the buildbot that failed (https://buildbot.python.org/#/builders/101/builds/5356) and take a look at the build logs.
  4. Check if the failure is related to this commit (48c70b8) or if it is a false positive.
  5. If the failure is related to this commit, please, reflect that on the issue and make a new Pull Request with a fix.

You can take a look at the buildbot page here:

https://buildbot.python.org/#/builders/101/builds/5356

Failed tests:

  • test_socket

Failed subtests:

  • testStream - test.test_socket.ThreadedVSOCKSocketStreamTest.testStream

Summary of the results of the build (if available):

==

Click to see traceback logs
Traceback (most recent call last):
  File "/home/buildbot/buildarea/3.x.cstratak-fedora-stable-ppc64le.lto-pgo/build/Lib/test/test_socket.py", line 550, in testStream
    msg = self.conn.recv(1024)
PermissionError: [Errno 13] Permission denied
All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@bedevere-bot

bedevere-bot commented Dec 19, 2024

Copy link
Copy Markdown

⚠️⚠️⚠️ Buildbot failure ⚠️⚠️⚠️

Hi! The buildbot PPC64LE Fedora Stable LTO 3.x has failed when building commit 48c70b8.

What do you need to do:

  1. Don't panic.
  2. Check the buildbot page in the devguide if you don't know what the buildbots are or how they work.
  3. Go to the page of the buildbot that failed (https://buildbot.python.org/#/builders/541/builds/4746) and take a look at the build logs.
  4. Check if the failure is related to this commit (48c70b8) or if it is a false positive.
  5. If the failure is related to this commit, please, reflect that on the issue and make a new Pull Request with a fix.

You can take a look at the buildbot page here:

https://buildbot.python.org/#/builders/541/builds/4746

Failed tests:

  • test_socket

Failed subtests:

  • testStream - test.test_socket.ThreadedVSOCKSocketStreamTest.testStream

Summary of the results of the build (if available):

==

Click to see traceback logs
Traceback (most recent call last):
  File "/home/buildbot/buildarea/3.x.cstratak-fedora-stable-ppc64le.lto/build/Lib/test/test_socket.py", line 550, in testStream
    msg = self.conn.recv(1024)
PermissionError: [Errno 13] Permission denied
All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@bedevere-bot

bedevere-bot commented Dec 19, 2024

Copy link
Copy Markdown

⚠️⚠️⚠️ Buildbot failure ⚠️⚠️⚠️

Hi! The buildbot PPC64LE Fedora Stable Refleaks 3.x has failed when building commit 48c70b8.

What do you need to do:

  1. Don't panic.
  2. Check the buildbot page in the devguide if you don't know what the buildbots are or how they work.
  3. Go to the page of the buildbot that failed (https://buildbot.python.org/#/builders/280/builds/1480) and take a look at the build logs.
  4. Check if the failure is related to this commit (48c70b8) or if it is a false positive.
  5. If the failure is related to this commit, please, reflect that on the issue and make a new Pull Request with a fix.

You can take a look at the buildbot page here:

https://buildbot.python.org/#/builders/280/builds/1480

Failed tests:

  • test_socket

Failed subtests:

  • testStream - test.test_socket.ThreadedVSOCKSocketStreamTest.testStream

Summary of the results of the build (if available):

==

Click to see traceback logs
Traceback (most recent call last):
  File "/home/buildbot/buildarea/3.x.cstratak-fedora-stable-ppc64le.refleak/build/Lib/test/test_socket.py", line 550, in testStream
    msg = self.conn.recv(1024)
PermissionError: [Errno 13] Permission denied
All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@markshannon

markshannon commented Dec 19, 2024

Copy link
Copy Markdown
Member

Looks good! Benchmark results:

  • ~1% improvement on free-threaded builds
  • ~neutral on default builds

I don't think a 0.3-0.5% slower on average with a 13% slowdown on the gc_traversal benchmark is "neutral".
It might be just noise, but the large slowdown on the gc_traversal benchmark suggests a real issue.

Could we revert this PR until we have a better understanding of what is going on here?

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@colesbury

colesbury commented Dec 19, 2024

Copy link
Copy Markdown
Contributor

The gc_traversal benchmark results sure looks like noise to me. That benchmark is dominated by list_traverse and functions in the GC, none of which have changed.

How about you run the benchmarks in the faster-cpython infrastructure and see if you get the same results?

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@corona10 corona10 added the topic-free-threading label Dec 22, 2024
srinivasreddy pushed a commit to srinivasreddy/cpython that referenced this pull request Dec 23, 2024
@corona10 @srinivasreddy
pythongh-115999: Enable BINARY_SUBSCR_GETITEM for free-threaded build (…
c83b6bf
…pythongh-127737)
srinivasreddy pushed a commit to srinivasreddy/cpython that referenced this pull request Jan 8, 2025
@corona10 @srinivasreddy
pythongh-115999: Enable BINARY_SUBSCR_GETITEM for free-threaded build (…
c791e1e
…pythongh-127737)
DavidChoi76 pushed a commit to realtime-dam-operation-using-AI/ras-commander that referenced this pull request Nov 9, 2026
@gpt-cmdr @claude
test(route): install the h5py read guard once; fix intermittent acces…
a2538ac
…s violation

watch_h5py_reads() assigned and restored h5py.AttributeManager.__getitem__ on
every context entry (several times per routed test). After ~1000 such class
modifications in one worker, CPython 3.13 runs out of type versions for the
class (MAX_VERSIONS_PER_CLASS); PyType_Modified() then returns early and no
longer clears the BINARY_SUBSCR_GETITEM cache, a borrowed pointer to the
per-context wrapper closure. Once that closure was freed, `obj.attrs[k]` ran
freed code (silently recording into a dead list) or faulted in
PyEval_EvalFrameDefault (cmp [rbx+88h] = func_version of the freed function).
This is the intermittent "access violation" in _fast_hdf_typed.read_attrs /
read_attr seen under pytest-xdist; it is not in HDF5 or the native engine.
CPython 3.14 fixed the cache (python/cpython#127737); 3.13.16 is affected.

The wrappers are now module-lifetime functions installed once per process
(reinstalled only if a restore removed them, refused if a foreign patch is
active); contexts only toggle recording. Regression tests cover wrapper
identity across contexts, nested contexts, foreign patches, and a subprocess
stress (900 contexts with allocator churn) that dies with 0xC0000005 on the
old guard.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Reviewers

@mpage mpage mpage approved these changes
@markshannon markshannon Awaiting requested review from markshannon markshannon is a code owner
@colesbury colesbury Awaiting requested review from colesbury
@ericsnowcurrently ericsnowcurrently Awaiting requested review from ericsnowcurrently ericsnowcurrently is a code owner
@Fidget-Spinner Fidget-Spinner Awaiting requested review from Fidget-Spinner Fidget-Spinner is a code owner

Uh oh!

There was an error while loading. Please reload this page.

Assignees

No one assigned

Labels

skip news topic-free-threading

Projects

None yet

Milestone

No milestone

Development

Successfully merging this pull request may close these issues.

Uh oh!

There was an error while loading. Please reload this page.

6 participants

@corona10 @mpage @bedevere-bot @Fidget-Spinner @markshannon @colesbury
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
You are visitor 01402520 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.