rkern / line_profiler

(OLD REPO) Line-by-line profiling for Python - Current repo ->
https://github.com/pyutils/line_profiler
Other
3.61k stars 254 forks source link

Python 3.7 StopIteration exception #152

Open Zannick opened 5 years ago

Zannick commented 5 years ago

PEP479 changed generator StopIteration behavior, so now putting @profile on a generator looks like this:

@profile
def iter_foo(a):
    for i in range(a):
        yield i

for i in iter_foo(5):
    print(i)
Traceback (most recent call last):
  File ".../line_profiler.py", line 102 in wrapper
    item = g.send(input)
StopIteration

The above exception was the direct cause of the following exception:

Traceback (most recent call last):
  File ".../kernprof", line 11, in <module>
    load_entry_point('line-profiler==2.1.1', 'console_scripts', 'kernprof')()
  File ".../kernprof.py", line 222, in main
    execfile(script_file, ns, ns)
  File ".../kernprof.py", line 35, in execfile
    exec_(compile(f.read(), filename, 'exec'), globals, locals)
  File ".../tmp.py", line 6, in <module>
    for i in iter_foo(5):
RuntimeError: generator raised StopIteration