Reject switch_context with sysmon core by itscloud0 · Pull Request #2202 · coveragepy/coveragepy · GitHub
Skip to content

Reject switch_context with sysmon core#2202

Open
itscloud0 wants to merge 4 commits into
coveragepy:mainfrom
itscloud0:fix-2200-sysmon-switch-context
Open

Reject switch_context with sysmon core#2202
itscloud0 wants to merge 4 commits into
coveragepy:mainfrom
itscloud0:fix-2200-sysmon-switch-context

Conversation

@itscloud0

@itscloud0 itscloud0 commented Jun 21, 2026

Copy link
Copy Markdown
Contributor

Summary

  • raise CoverageException if switch_context() is called while running on core=sysmon
  • keep the existing startup-time fallback for configured dynamic contexts unchanged
  • document that explicit context switching requires ctrace or pytrace, and add a regression test

Problem

switch_context() worked under ctrace, but under sysmon a shared line hit by two contexts only kept the first one. The API path had no guard, so Python 3.14's default sysmon core could silently produce wrong context data.

Solution

Instead of silently downgrading to a slower tracing core after measurement has already started, reject the API call and tell users to choose core=ctrace or core=pytrace explicitly when they need dynamic contexts.

@itscloud0 itscloud0 marked this pull request as ready for review June 21, 2026 21:41
@nedbat

nedbat commented Jun 22, 2026

Copy link
Copy Markdown
Member

@itscloud0 itscloud0 changed the title Handle switch_context after sysmon start Reject switch_context with sysmon core Jun 23, 2026
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.

2 participants