co_instrumentation and co_monitoring Unexpectedly Set
Nobody has claimed this yet.
- Dominant language
- Python
- Stars
- 77.2k
- Forks
- 35.9k
- PR merge metrics
- PR metrics pending
Description
Bug report
Bug description:
I ran into the following problematic case with gh-133221 (which had to be reverted):
import sys
import _testinternalcapi
def foo():
pass
def trace_temporarily():
sys._getframe().f_trace_opcodes = True
sys.settrace(print)
sys.settrace(None)
sys._getframe().f_trace_opcodes = False
trace_temporarily()
_testinternalcapi.verify_stateless_code(foo.__code__)
foo()
_testinternalcapi.verify_stateless_code(foo.__code__) # fails
(See https://github.com/python/cpython/pull/133221#issuecomment-2853467104.)
I would expect co_instrumentation and co_monitoring to have remained NULL.
CC @markshannon
CPython versions tested on:
CPython main branch
Operating systems tested on:
No response
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Reproduce the provided example on the CPython main branch, focusing on sys.settrace, f_trace_opcodes, and _testinternalcapi.verify_stateless_code. Trace how the code object's co_instrumentation and co_monitoring state changes during the temporary tracing, and confirm the fix by ensuring both remain NULL and verification passes after foo() runs.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- python
- Domain
- compilers
- Issue type
- Bug
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 38/100