Skip to content

co_instrumentation and co_monitoring Unexpectedly Set #133524

Open
@ericsnowcurrently

Description

@ericsnowcurrently

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 #133221 (comment).)

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    interpreter-core(Objects, Python, Grammar, and Parser dirs)type-bugAn unexpected behavior, bug, or error

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions