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-140936: Fix JIT assertion crash at finalization if some generator is alive by efimov-mikhail · Pull Request #140969 · python/cpython

Conversation

@efimov-mikhail

@efimov-mikhail efimov-mikhail commented Nov 3, 2025 •
edited by bedevere-app Bot
Loading

Uh oh!

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

Copy link
Copy Markdown
Member

I've removed setting interp->jit to false at finalization.
Because in rare case it may be a problem when some optimized code is used after finalize_modules.

New test needs subprocess since we have assertion crash only at the finalization stage.
On release builds there was no real problem, and test passed with this fix and without it.

  • Issue: Assertion failure in Python/optimizer.c _PyOptimizer_Optimize in JIT #140936

Sorry, something went wrong.

Uh oh!

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

All reactions
efimov-mikhail added 2 commits November 4, 2025 01:03
@efimov-mikhail
Possible solution
cc1f1e9
@efimov-mikhail
Test added
937b990
@efimov-mikhail
efimov-mikhail requested review from ZeroIntensity and ericsnowcurrently as code owners November 3, 2025 22:42
@bedevere-app bedevere-app Bot added the awaiting review label Nov 3, 2025
@bedevere-app bedevere-app Bot mentioned this pull request Nov 3, 2025
Assertion failure in Python/optimizer.c _PyOptimizer_Optimize in JIT #140936
Closed
@efimov-mikhail
efimov-mikhail requested review from Fidget-Spinner and sergey-miryanov November 3, 2025 22:42
@efimov-mikhail efimov-mikhail added skip news needs backport to 3.14 bugs and security fixes labels Nov 3, 2025
@Fidget-Spinner

Fidget-Spinner commented Nov 3, 2025

Copy link
Copy Markdown
Member

Hmm I think this isn't the problem.

The problem might be that JUMP_BACKWARD is specialized to JUMP_BACKWARD_JIT.

Following that, finalization happens, turning the JIT off. However, some of the JUMP_BACKWARD still remains as JUMP_BACKWARD_JIT.

This causes optimizer to be triggered on JUMP_BACKWARD_JIT.

The real fix should be to check if interp->jit is false in _PyOptimizer_Optimize and immediately return if not.

All reactions

Sorry, something went wrong.

Uh oh!

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

@efimov-mikhail

efimov-mikhail commented Nov 3, 2025

Copy link
Copy Markdown
Member Author

CC @brandtbucher as author of #129194

All reactions

Sorry, something went wrong.

Uh oh!

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

@efimov-mikhail
efimov-mikhail requested a review from markshannon as a code owner November 3, 2025 23:07
@efimov-mikhail

efimov-mikhail commented Nov 3, 2025

Copy link
Copy Markdown
Member Author

The real fix should be to check if interp->jit is false in _PyOptimizer_Optimize and immediately return if not.

Ok, I've provided this fix.

All reactions

Sorry, something went wrong.

Uh oh!

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

@Fidget-Spinner

Fidget-Spinner commented Nov 3, 2025

Copy link
Copy Markdown
Member

@efimov-mikhail thanks. Just checking: does it pass the test on your system? I didn't test it but I think it should.

All reactions

Sorry, something went wrong.

Uh oh!

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

@efimov-mikhail
Another solution
688f063
@efimov-mikhail

efimov-mikhail commented Nov 3, 2025

Copy link
Copy Markdown
Member Author

On my system new test passes with this fix and fails without it on debug build.
And all others tests also pass.

Fidget-Spinner 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.

Fidget-Spinner
Fidget-Spinner reviewed Nov 3, 2025
View reviewed changes
Comment thread Lib/test/test_capi/test_opt.py Resolved

Uh oh!

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

@efimov-mikhail
New line fix in test
39f9bc3
Fidget-Spinner
Fidget-Spinner approved these changes Nov 4, 2025
View reviewed changes
@bedevere-app bedevere-app Bot added awaiting merge and removed awaiting review labels Nov 4, 2025
ZeroIntensity
ZeroIntensity reviewed Nov 4, 2025
View reviewed changes
Comment thread Lib/test/test_capi/test_opt.py Resolved

Uh oh!

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

@efimov-mikhail
efimov-mikhail requested a review from ZeroIntensity November 4, 2025 08:17
@efimov-mikhail
Simplify test
28c07d6
sergey-miryanov
sergey-miryanov reviewed Nov 4, 2025
View reviewed changes
Comment thread Lib/test/test_capi/test_opt.py Resolved

Uh oh!

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

sergey-miryanov
sergey-miryanov approved these changes Nov 4, 2025
View reviewed changes

@sergey-miryanov sergey-miryanov 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.

LGTM

Sorry, something went wrong.

Uh oh!

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

efimov-mikhail reacted with heart emoji
All reactions
  • ❤️ 1 reaction
Fidget-Spinner
Fidget-Spinner reviewed Nov 6, 2025
View reviewed changes
Comment thread Lib/test/test_capi/test_opt.py Resolved

Uh oh!

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

@efimov-mikhail
Test improvement
e7a261a
@efimov-mikhail

efimov-mikhail commented Nov 12, 2025

Copy link
Copy Markdown
Member Author

Friendly ping, @Fidget-Spinner, @ZeroIntensity .
Can we merge this or there's something else that I have to address?

All reactions

Sorry, something went wrong.

Uh oh!

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

Fidget-Spinner
Fidget-Spinner reviewed Nov 12, 2025
View reviewed changes
Comment thread Python/optimizer.c Resolved

Uh oh!

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

efimov-mikhail added 2 commits November 12, 2025 16:57
@efimov-mikhail
Merge branch 'main' into issue-140936-jit-crash-at-finalization
21a6e2b
@efimov-mikhail
Some comment at _PyOptimizer_Optimize
6be7a84
@Fidget-Spinner
Fidget-Spinner merged commit 35ed3e4 into python:main Nov 12, 2025
62 checks passed

Uh oh!

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

@miss-islington-app

miss-islington-app Bot commented Nov 12, 2025

Copy link
Copy Markdown

Thanks @efimov-mikhail for the PR, and @Fidget-Spinner for merging it 🌮🎉.. I'm working now to backport this PR to: 3.14.
🐍🍒⛏🤖 I'm not a witch! I'm not a witch!

All reactions

Sorry, something went wrong.

Uh oh!

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

@bedevere-app bedevere-app Bot removed the awaiting merge label Nov 12, 2025
@miss-islington-app

miss-islington-app Bot commented Nov 12, 2025

Copy link
Copy Markdown

Sorry, @efimov-mikhail and @Fidget-Spinner, I could not cleanly backport this to 3.14 due to a conflict.
Please backport using cherry_picker on command line.

cherry_picker 35ed3e4cedc8aef3936da81a6b64e90374532b13 3.14
All reactions

Sorry, something went wrong.

Uh oh!

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

@miss-islington-app miss-islington-app Bot assigned Fidget-Spinner Nov 12, 2025
@efimov-mikhail

efimov-mikhail commented Nov 12, 2025

Copy link
Copy Markdown
Member Author

Thanks for the merge, @Fidget-Spinner. I'll provide manual backport for 3.14.

Fidget-Spinner reacted with heart emoji
All reactions
  • ❤️ 1 reaction

Sorry, something went wrong.

Uh oh!

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

efimov-mikhail added a commit to efimov-mikhail/cpython that referenced this pull request Nov 13, 2025
@efimov-mikhail
pythongh-140936: Fix JIT assertion crash at finalization if some gene…
e996564
…rator is alive (pythonGH-140969)
@bedevere-app

bedevere-app Bot commented Nov 13, 2025

Copy link
Copy Markdown

GH-141494 is a backport of this pull request to the 3.14 branch.

All reactions

Sorry, something went wrong.

Uh oh!

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

@bedevere-app bedevere-app Bot removed the needs backport to 3.14 bugs and security fixes label Nov 13, 2025
Fidget-Spinner pushed a commit that referenced this pull request Nov 13, 2025
@efimov-mikhail
[3.14] gh-140936: Fix JIT assertion crash at finalization if some gen…
48b7d75
…erator is alive (GH-140969) (GH-141494)

gh-140936: Fix JIT assertion crash at finalization if some generator is alive (GH-140969)
CuriousLearner added a commit to CuriousLearner/cpython that referenced this pull request Nov 13, 2025
@CuriousLearner
Merge branch 'main' into fix-issue21914
b9f473c
* main: (463 commits)
  pythongh-140601: Add ResourceWarning to iterparse when not closed (pythonGH-140603)
  pythongh-137969: Fix double evaluation of `ForwardRef`s which rely on globals (python#140974)
  pythongh-139109: A new tracing JIT compiler frontend for CPython (pythonGH-140310)
  pythongh-141004: Document `PyErr_RangedSyntaxLocationObject` (python#141521)
  pythongh-140873: Add support of non-descriptor callables in functools.singledispatchmethod() (pythonGH-140884)
  pythongh-139653: Add PyUnstable_ThreadState_SetStackProtection() (python#139668)
  pythongh-141004: Document `PyCode_Optimize` (pythonGH-141378)
  pythongh-141004: Document C APIs for dictionary keys, values, and items (pythonGH-141009)
  pythongh-137959: Fix `TIER1_TO_TIER2` macro name in JIT InternalDocs (pythonGH-141496)
  pythongh-139871: Add `bytearray.take_bytes([n])` to efficiently extract `bytes` (pythonGH-140128)
  pythongh-140601: Refactor ElementTree.iterparse() tests (pythonGH-141499)
  pythongh-135801: Add the module parameter to compile() etc (pythonGH-139652)
  pythongh-140260: fix data race in `_struct` module initialization with subinterpreters (python#140909)
  pythongh-137109: refactor warning about threads when forking (python#141438)
  pythongh-141004: Document `PyRun_InteractiveOneObject` (pythonGH-141405)
  pythongh-124111: Fix TCL 9 thread detection (pythonGH-128103)
  pythongh-141442: Add escaping to iOS testbed arguments (python#141443)
  pythongh-140936: Fix JIT assertion crash at finalization if some generator is alive (pythonGH-140969)
  Add details about JIT build infrastructure and updating dependencies to `Tools/jit` (python#141167)
  pythongh-141412: Use reliable target URL for urllib example (pythonGH-141428)
  ...
CuriousLearner added a commit to CuriousLearner/cpython that referenced this pull request Nov 14, 2025
@CuriousLearner
Merge branch 'main' of github.com:python/cpython into fix-Issue18387
c46ecc5
* 'main' of github.com:python/cpython: (464 commits)
  pythongh-140601: Add ResourceWarning to iterparse when not closed (pythonGH-140603)
  pythongh-137969: Fix double evaluation of `ForwardRef`s which rely on globals (python#140974)
  pythongh-139109: A new tracing JIT compiler frontend for CPython (pythonGH-140310)
  pythongh-141004: Document `PyErr_RangedSyntaxLocationObject` (python#141521)
  pythongh-140873: Add support of non-descriptor callables in functools.singledispatchmethod() (pythonGH-140884)
  pythongh-139653: Add PyUnstable_ThreadState_SetStackProtection() (python#139668)
  pythongh-141004: Document `PyCode_Optimize` (pythonGH-141378)
  pythongh-141004: Document C APIs for dictionary keys, values, and items (pythonGH-141009)
  pythongh-137959: Fix `TIER1_TO_TIER2` macro name in JIT InternalDocs (pythonGH-141496)
  pythongh-139871: Add `bytearray.take_bytes([n])` to efficiently extract `bytes` (pythonGH-140128)
  pythongh-140601: Refactor ElementTree.iterparse() tests (pythonGH-141499)
  pythongh-135801: Add the module parameter to compile() etc (pythonGH-139652)
  pythongh-140260: fix data race in `_struct` module initialization with subinterpreters (python#140909)
  pythongh-137109: refactor warning about threads when forking (python#141438)
  pythongh-141004: Document `PyRun_InteractiveOneObject` (pythonGH-141405)
  pythongh-124111: Fix TCL 9 thread detection (pythonGH-128103)
  pythongh-141442: Add escaping to iOS testbed arguments (python#141443)
  pythongh-140936: Fix JIT assertion crash at finalization if some generator is alive (pythonGH-140969)
  Add details about JIT build infrastructure and updating dependencies to `Tools/jit` (python#141167)
  pythongh-141412: Use reliable target URL for urllib example (pythonGH-141428)
  ...
CuriousLearner added a commit to CuriousLearner/cpython that referenced this pull request Nov 14, 2025
@CuriousLearner
Merge branch 'main' of github.com:python/cpython into fix-issue24255
c240289
* 'main' of github.com:python/cpython: (464 commits)
  pythongh-140601: Add ResourceWarning to iterparse when not closed (pythonGH-140603)
  pythongh-137969: Fix double evaluation of `ForwardRef`s which rely on globals (python#140974)
  pythongh-139109: A new tracing JIT compiler frontend for CPython (pythonGH-140310)
  pythongh-141004: Document `PyErr_RangedSyntaxLocationObject` (python#141521)
  pythongh-140873: Add support of non-descriptor callables in functools.singledispatchmethod() (pythonGH-140884)
  pythongh-139653: Add PyUnstable_ThreadState_SetStackProtection() (python#139668)
  pythongh-141004: Document `PyCode_Optimize` (pythonGH-141378)
  pythongh-141004: Document C APIs for dictionary keys, values, and items (pythonGH-141009)
  pythongh-137959: Fix `TIER1_TO_TIER2` macro name in JIT InternalDocs (pythonGH-141496)
  pythongh-139871: Add `bytearray.take_bytes([n])` to efficiently extract `bytes` (pythonGH-140128)
  pythongh-140601: Refactor ElementTree.iterparse() tests (pythonGH-141499)
  pythongh-135801: Add the module parameter to compile() etc (pythonGH-139652)
  pythongh-140260: fix data race in `_struct` module initialization with subinterpreters (python#140909)
  pythongh-137109: refactor warning about threads when forking (python#141438)
  pythongh-141004: Document `PyRun_InteractiveOneObject` (pythonGH-141405)
  pythongh-124111: Fix TCL 9 thread detection (pythonGH-128103)
  pythongh-141442: Add escaping to iOS testbed arguments (python#141443)
  pythongh-140936: Fix JIT assertion crash at finalization if some generator is alive (pythonGH-140969)
  Add details about JIT build infrastructure and updating dependencies to `Tools/jit` (python#141167)
  pythongh-141412: Use reliable target URL for urllib example (pythonGH-141428)
  ...
StanFromIreland pushed a commit to StanFromIreland/cpython that referenced this pull request Dec 6, 2025
@efimov-mikhail @StanFromIreland
pythongh-140936: Fix JIT assertion crash at finalization if some gene…
3ff68f7
…rator is alive (pythonGH-140969)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Reviewers

@Fidget-Spinner Fidget-Spinner Fidget-Spinner approved these changes
@sergey-miryanov sergey-miryanov sergey-miryanov approved these changes
@ericsnowcurrently ericsnowcurrently Awaiting requested review from ericsnowcurrently
@markshannon markshannon Awaiting requested review from markshannon markshannon is a code owner
@ZeroIntensity ZeroIntensity Awaiting requested review from ZeroIntensity

Uh oh!

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

Assignees

@Fidget-Spinner Fidget-Spinner

Labels

skip news

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.

4 participants

@efimov-mikhail @Fidget-Spinner @sergey-miryanov @ZeroIntensity
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 01402503 — 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.