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

AssertionError when running profile on code containing generator expression #110514

Closed
chgnrdv opened this issue Oct 8, 2023 · 2 comments
Closed
Assignees
Labels
3.12 bugs and security fixes 3.13 new features, bugs and security fixes type-bug An unexpected behavior, bug, or error

Comments

@chgnrdv
Copy link
Contributor

chgnrdv commented Oct 8, 2023

Bug report

Bug description:

Bisected to 411b169.

Minimal repro (save it to file and run as python -m profile script.py):

next(i for i in range(10))

Output:

Exception ignored in: <generator object <genexpr> at 0x7f48fac29010>
Traceback (most recent call last):
  File "/home/radislav/projects/cpython/Lib/profile.py", line 209, in trace_dispatch_i
    if self.dispatch[event](self, frame, t):
       ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/radislav/projects/cpython/Lib/profile.py", line 293, in trace_dispatch_return
    assert frame is self.cur[-2].f_back, ("Bad return", self.cur[-3])
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^
AssertionError: ('Bad return', ('script.py', 1, '<module>'))
         5 function calls in 0.114 seconds

   Ordered by: standard name

   ncalls  tottime  percall  cumtime  percall filename:lineno(function)
        1    0.000    0.000    0.114    0.114 :0(exec)
        1    0.000    0.000    0.000    0.000 :0(next)
        1    0.000    0.000    0.114    0.114 profile:0(<code object <module> at 0x7f48faba08c0, file "script.py", line 1>)
        0    0.000             0.000          profile:0(profiler)
        1    0.000    0.000    0.000    0.000 script.py:1(<genexpr>)
        1    0.114    0.114    0.114    0.114 script.py:1(<module>)

CPython versions tested on:

3.12, CPython main branch

Operating systems tested on:

Linux

Linked PRs

@chgnrdv chgnrdv added the type-bug An unexpected behavior, bug, or error label Oct 8, 2023
@chgnrdv
Copy link
Contributor Author

chgnrdv commented Oct 8, 2023

cc @markshannon

@AlexWaygood AlexWaygood added 3.12 bugs and security fixes 3.13 new features, bugs and security fixes labels Oct 8, 2023
@gaogaotiantian gaogaotiantian self-assigned this Oct 8, 2023
@gaogaotiantian
Copy link
Member

This is very similar to #106152. Should've caught it back then. Fix PR is made.

miss-islington pushed a commit to miss-islington/cpython that referenced this issue Oct 9, 2023
…0524)

(cherry picked from commit dd4bb05)

Co-authored-by: Tian Gao <gaogaotiantian@hotmail.com>
Yhg1s pushed a commit that referenced this issue Oct 9, 2023
…#110541)

gh-110514: Add PY_THROW to `sys.setprofile` events (GH-110524)
(cherry picked from commit dd4bb05)

Co-authored-by: Tian Gao <gaogaotiantian@hotmail.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
3.12 bugs and security fixes 3.13 new features, bugs and security fixes type-bug An unexpected behavior, bug, or error
Projects
None yet
Development

No branches or pull requests

3 participants