Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Merged
merged 2 commits into from Jan 5, 2024

Conversation

markshannon
Copy link
Member

@markshannon markshannon commented Jan 3, 2024

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

@Eclips4 Eclips4 added the interpreter-core (Objects, Python, Grammar, and Parser dirs) label Jan 3, 2024
@nedbat
Copy link
Member

nedbat commented Jan 4, 2024

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
Copy link
Member

nedbat commented Jan 4, 2024

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
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
32 checks passed
@markshannon markshannon deleted the no-unwind-c-frames branch January 5, 2024 09:45
@gaogaotiantian
Copy link
Contributor

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

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.

None yet

5 participants