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-159117: Preserve sys.setprofile callbacks when destroying a tracing profiler by Cha-Imaa · Pull Request #159664 · python/cpython

Conversation

@Cha-Imaa

@Cha-Imaa Cha-Imaa commented Oct 18, 2026 •
edited by bedevere-app Bot
Loading

Uh oh!

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

Copy link
Copy Markdown

Fixes #159117.

profiler_dealloc() still called _PyEval_SetProfile(tstate, NULL, NULL), although _lsprof now uses sys.monitoring. Destroying an enabled profiler after its monitoring callbacks have been released therefore cleared an unrelated sys.setprofile() callback.

When a cyclic profiler is collected during ProfileTest.do_profiling(), this can stop the pure Python profiler before it has recorded all calls, producing empty or partial statistics.

Remove the obsolete cleanup and its unused headers. Monitoring callbacks hold references to the profiler while registered, so deallocation does not need to unregister them. Add a deterministic regression test that releases an enabled profiler's monitoring callbacks, destroys it, and verifies that an independent sys.setprofile() callback remains installed. Include a NEWS entry.

Validation on a Windows AMD64 CPython 3.16 debug build:

  • The new regression test fails before the C change (sys.getprofile() returns None) and passes afterward.
  • PCbuild\amd64\python_d.exe -m test -j2 test_profile test_profiling test_sys_setprofile test_monitoring test_pstats passes (629 tests reported, 16 skipped).
  • PCbuild\amd64\python_d.exe -m test -j1 -R3:3 test_profile test.test_profiling.test_tracing_profiler passes with no detected reference leaks.
  • Ruff, sphinx-lint, git diff --cached --check, and CPython patchcheck pass.

The original Windows PGO tail-call and s390x buildbot configurations were not tested locally.

  • Issue: test_profile: ProfileTest.test_cprofile() failed on AMD64 Windows PGO Tailcall 3.x #159117

Sorry, something went wrong.

Uh oh!

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

All reactions
@Cha-Imaa
pythongh-159117: Preserve sys.setprofile callbacks when destroying a …
8f8ca16
…tracing profiler
@Cha-Imaa
Cha-Imaa requested a review from pablogsal as a code owner October 18, 2026 09:43
@python-cla-bot

python-cla-bot Bot commented Oct 18, 2026 •
edited
Loading

Uh oh!

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

Copy link
Copy Markdown

All commit authors signed the Contributor License Agreement.

CLA signed

All reactions

Sorry, something went wrong.

Uh oh!

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

@bedevere-app bedevere-app Bot mentioned this pull request Oct 18, 2026
test_profile: ProfileTest.test_cprofile() failed on AMD64 Windows PGO Tailcall 3.x #159117
Open
@bedevere-app bedevere-app Bot added the awaiting review label Oct 18, 2026
Cha-Imaa added 3 commits October 18, 2026 15:07
@Cha-Imaa
Merge remote-tracking branch 'origin/main' into pythongh-159117-profi…
b79a6f4
…ler-dealloc
@Cha-Imaa
Merge branch 'main' into pythongh-159117-profiler-dealloc
4f1bdc9
@Cha-Imaa
Merge branch 'main' into pythongh-159117-profiler-dealloc
6b3b9b2
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Reviewers

@pablogsal pablogsal Awaiting requested review from pablogsal pablogsal is a code owner

Uh oh!

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

Assignees

No one assigned

Labels

awaiting review

Projects

None yet

Milestone

No milestone

Development

Successfully merging this pull request may close these issues.

test_profile: ProfileTest.test_cprofile() failed on AMD64 Windows PGO Tailcall 3.x

Uh oh!

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

1 participant

@Cha-Imaa
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.