Skip to content

No audit hook for sys.monitoring tools being cleared / freed #159379

Open

Description

@godlygeek

Bug report

The sys.monitoring.register_callback audit hook fires when a sys.monitoring callback gets installed or uninstalled by a call to sys.monitoring.register_callback, but there's no audit hook that fires when a sys.monitoring callback gets uninstalled by a call to sys.monitoring.clear_tool_id or sys.monitoring.free_tool_id.

Is this intentional, or an oversight? It seems strange that there are two ways to uninstall a tool's callback, one of which fires an audit event and one of which doesn't.

I was hoping to use audit hooks to detect when a sys.monitoring tool was disabled in the middle of trying to do its work, but no audit event firing for sys.monitoring.clear_tool_id makes that impossible.

CPython versions tested on:

3.15

Operating systems tested on:

Linux

Activity

  1. added
    type-featureA feature request or enhancement
    interpreter-core(Objects, Python, Grammar, and Parser dirs)
    and removed
    type-bugAn unexpected behavior, bug, or error
    on Oct 14, 2026
  2. picnixz commented on Oct 14, 2026

    @picnixz
    Member

    I wouldn't consider it as a bug and rather as a feature for now. The problem is: what should we actually fire? the tool id and the corresponding function? sys.monitoring.register_callback only sends the func but doesn't explain what is done (we don't know the event for instance), so I already consider this as a bit partial. IMO a more precise event could be fired for that.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    interpreter-core(Objects, Python, Grammar, and Parser dirs)type-featureA feature request or enhancement

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions