Skip to content

GH-113486: Do not emit spurious PY_UNWIND events for optimized calls to classes.#113680

Merged
markshannon merged 2 commits into
python:mainfrom
faster-cpython:no-unwind-c-frames
Jan 5, 2024
Merged

GH-113486: Do not emit spurious PY_UNWIND events for optimized calls to classes.#113680
markshannon merged 2 commits into
python:mainfrom
faster-cpython:no-unwind-c-frames

Conversation

@markshannon

@markshannon markshannon commented Jan 3, 2024

Copy link
Copy Markdown
Member

Adds the CO_NO_MONITORING_EVENTS flag for use by shim frame code objects and similar, to avoid monitoring events.

Comment thread Misc/NEWS.d/next/Core and Builtins/2023-12-31-07-46-01.gh-issue-113486.uki19C.rst Outdated
Comment thread Python/specialize.c
@Eclips4 Eclips4 added the interpreter-core (Objects, Python, Grammar, and Parser dirs) label Jan 3, 2024
@nedbat

nedbat commented Jan 4, 2024

Copy link
Copy Markdown
Member

Thanks for the quick action. I took the liberty of testing this branch. The events reported to the settrace function is changed:

import linecache, sys

def trace(frame, event, arg):
    # The weird globals here is to avoid a NameError on shutdown...
    if frame.f_code.co_filename == globals().get("__file__"):
        lineno = frame.f_lineno
        line = linecache.getline(__file__, lineno).rstrip()
        print("{} {}: {}".format(event[:4], lineno, line))
    return trace

print(sys.version)
sys.settrace(trace)

def gen():
    print(2)
    yield 3
    print(4)

print(next(gen()))

Running with 3.12:

3.12.1 (main, Dec  8 2023, 20:58:19) [Clang 15.0.0 (clang-1500.0.40.1)]
call 14: def gen():
line 15:     print(2)
2
line 16:     yield 3
retu 16:     yield 3
call 16:     yield 3
exce 16:     yield 3
retu 16:     yield 3
3

Running with this branch:

3.13.0a2+ (heads/pr/113680:e92fd7b816, Jan  4 2024, 10:22:55) [Clang 15.0.0 (clang-1500.1.0.2.5)]
call 14: def gen():
line 15:     print(2)
2
line 16:     yield 3
retu 16:     yield 3
3

Do you mean to skip the return and call events from the yield?

@nedbat

nedbat commented Jan 4, 2024

Copy link
Copy Markdown
Member

BTW, the 3.13 behavior also happens with 3.13.0a2, so it's not due to the change in this branch, but seems related?

3.13.0a2 (main, Nov 24 2023, 14:53:47) [Clang 15.0.0 (clang-1500.0.40.1)]
call 14: def gen():
line 15:     print(2)
2
line 16:     yield 3
retu 16:     yield 3
3

@markshannon

Copy link
Copy Markdown
Member Author

@nedbat
I've opened #113728 for the difference between 3.12 and 3.13.

@markshannon
markshannon merged commit 0ae60b6 into python:main Jan 5, 2024
@markshannon
markshannon deleted the no-unwind-c-frames branch January 5, 2024 09:45
@gaogaotiantian

Copy link
Copy Markdown
Member

Sorry I was traveling and did not have a reliable network access. But the change looks good to me.

kulikjak pushed a commit to kulikjak/cpython that referenced this pull request Jan 22, 2024
aisk pushed a commit to aisk/cpython that referenced this pull request Feb 11, 2024
Glyphack pushed a commit to Glyphack/cpython that referenced this pull request Sep 2, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

interpreter-core (Objects, Python, Grammar, and Parser dirs)

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants