Skip to content

AssertionError when running profile on code containing generator expression #110514

Closed

Description

@chgnrdv

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

Activity

  1. added
    type-bugAn unexpected behavior, bug, or error
    on Oct 8, 2023
  2. chgnrdv commented on Oct 8, 2023

    @chgnrdv
    ContributorAuthor
  3. gaogaotiantian commented on Oct 8, 2023

    @gaogaotiantian
    Member

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

  4. added a commit that references this issue on Oct 9, 2023
  5. added a commit that references this issue on Oct 9, 2023
  6. added a commit that references this issue on Oct 9, 2023
  7. added a commit that references this issue on Sep 2, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Labels

3.12only security fixes3.13only security fixestype-bugAn unexpected behavior, bug, or error

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions