Skip to content

sys.monitoring fails to run callback on small function calls #136888

@sczi

Description

@sczi

Bug report

Bug description:

With a basic use of sys.monitoring to report calls of a function, everything works as expected:

from sys import monitoring


def foo():
    for i in range(5):
        if i > 4:
            return "in foo"


monitoring.use_tool_id(0, "test")


def tracer(code, instruction_offset, c, arg0):
    print("got args: ", arg0)


monitoring.register_callback(0, monitoring.events.CALL, tracer)
monitoring.set_local_events(0, foo.__code__, monitoring.events.CALL)

print(foo())

but if we modify foo to just be:

def foo():
    return "in foo"

now tracer doesn't run. python supposedly doesn't do any inlining, but it seems that on simple trivially inlineable functions, that the CALL event isn't being triggered?

I tested this on python3.13.3 and against the latest git (Python 3.15.0a0 (heads/main:aec7f5f8b2e))

CPython versions tested on:

CPython main branch

Operating systems tested on:

Linux

Metadata

Metadata

Assignees

No one assigned

    Labels

    stdlibStandard Library Python modules in the Lib/ directorytype-bugAn unexpected behavior, bug, or error

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions