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

    stdlibPython modules in the Lib dirtype-bugAn unexpected behavior, bug, or error

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions

      pFad - Phonifier reborn

      Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

      Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


      Alternative Proxies:

      Alternative Proxy

      pFad Proxy

      pFad v3 Proxy

      pFad v4 Proxy