Skip to content

Instrumentation assertion failure when calling the registered handler explicitly #122247

Closed
@pschanely

Description

@pschanely

Bug report

Bug description:

On my mac M1 Sonoma (14.5), Python 3.13.0b4, I see this crash when registering an opcode monitor, calling the handler explicitly while it's enabled, and then restarting events. To reproduce:

import sys

def mymonitor(code, instruction_offset):
    pass

tool_id = 4
sys.monitoring.use_tool_id(tool_id, "mytool")
sys.monitoring.register_callback(
    tool_id,
    sys.monitoring.events.INSTRUCTION,
    mymonitor,
)
sys.monitoring.set_events(tool_id, sys.monitoring.events.INSTRUCTION)
mymonitor(None, 0)  # call the *same* handler while it is registered                                                                                                                                                                                                                       
sys.monitoring.restart_events()

Triggers an assertion failure (my minimal debugging suggests it's about some inconsistency with the "instrumentation_version"):

$ 3.13.0b4-debug/bin/python -X dev repro.py
Assertion failed: (debug_check_sanity(tstate->interp, code)), function _Py_call_instrumentation_instruction, file instrumentation.c, line 1347.
Fatal Python error: Aborted

Current thread 0x00000002064b0c00 (most recent call first):
  File "/Users/phillipschanely/proj/CrossHair/repro.py", line 4 in mymonitor
  File "/Users/phillipschanely/proj/CrossHair/repro.py", line 16 in <module>
zsh: abort      /Users/phillipschanely/.pyenv/versions/3.13.0b4-debug/bin/python -X dev 

Thanks for investigating!

CPython versions tested on:

3.13

Operating systems tested on:

macOS

Linked PRs

Metadata

Metadata

Labels

type-bugAn unexpected behavior, bug, or error

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions