Skip to content

Instrumentation assertion failure when calling the registered handler explicitly #122247

Closed

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

Activity

  1. gaogaotiantian commented on Jul 24, 2024

    @gaogaotiantian
    Member

    Confirmed on main. I'll take a look at it.

  2. added a commit that references this issue on Aug 8, 2024
  3. added a commit that references this issue on Aug 8, 2024
  4. added a commit that references this issue on Aug 16, 2024
  5. added a commit that references this issue on Aug 22, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

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