Skip to content

fix: preserve frame timing until exception unwind - #449

Open
manav4u wants to merge 5 commits into
pyutils:mainfrom
manav4u:fix-exception-unwind-445
Open

manav4u wants to merge 5 commits into
pyutils:mainfrom
manav4u:fix-exception-unwind-445

Conversation

@manav4u

@manav4u manav4u commented Nov 10, 2026 •

Copy link
Copy Markdown

Fixes #445.

Finish frame timing on PY_UNWIND, not RAISE or RERAISE. A raised exception can still be handled inside the same frame without another line event. Clearing the timing record at the raise loses time spent in an unprofiled context manager's __exit__.

The regression tests cover direct raises, exceptions from an unprofiled callee, explicit reraises and exceptions during finally, with suppression on and off, under both tracing backends. They check exit-time attribution, continuation, frame cleanup and exclusion of later idle time. Two further tests cover forwarding an existing unwind callback and restoring callbacks/event masks. The legacy backend and shared line-timing algorithm are unchanged.

Updated November 22 against main 958d4a8 with an additive merge, preserving the branch history. The fix now lives in the split monitoring modules and keeps upstream's cached event bindings, nonbinding callbacks and event restart behavior.

Fresh local validation on Linux, CPython 3.12.16 / Cython 3.3.1:

  • Rebuilt the extension and ran the full tests directory: 338 passed, 3 skipped, 1 xfailed.
  • git diff --check passes.
  • The run reports the existing unclosed-file warning in test_docs_conf.

These are current-head local results, not remote CI or an all-platform claim. Other Python versions, other operating systems, minimum-Cython compatibility, type checks and documentation builds were not rerun for this update. No performance claim is made.

Investigation, patch and tests were AI-assisted; independent human review of the implementation is pending.

@codecov

codecov Bot commented Nov 11, 2026 •

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 81.56%. Comparing base (0c932ab) to head (ed4a90c).
⚠️ Report is 5 commits behind head on main.

Additional details and impacted files

Impacted file tree graph

@@            Coverage Diff             @@
##             main     #449      +/-   ##
==========================================
- Coverage   85.12%   81.56%   -3.57%     
==========================================
  Files          21       21              
  Lines        2413     2484      +71     
  Branches      376      410      +34     
==========================================
- Hits         2054     2026      -28     
- Misses        259      343      +84     
- Partials      100      115      +15     

see 9 files with indirect coverage changes


Continue to review full report in Codecov by Harness.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update d3400d7...ed4a90c. Read the comment docs.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@Erotemic

Copy link
Copy Markdown
Member

This will need to be rebased on main.

@manav4u

manav4u commented Nov 22, 2026

Copy link
Copy Markdown
Author

Thanks @Erotemic, and sorry I left this waiting. Updated for current main now, with an additive merge rather than a history rewrite. The fix is adapted to the split monitoring modules, keeping main's callback bindings and event restart behavior intact.

Rebuilt on CPython 3.12.16 / Cython 3.3.1 and reran the full tests directory: 338 passed, 3 skipped, 1 xfailed. The description now reflects this update and its validation limits.

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Investigate exception-event handling in sys.monitoring profiling

2 participants