nschloe / tuna

:fish: Python profile viewer

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Uncaught StopIteration exception

kbrose opened this issue · comments

Just installed tuna and it doesn't seem to be working on my machine.

> pip install tuna
> python -m cProfile -o stat.prof myscript.py
> tuna stat.prof
Traceback (most recent call last):
  File "c:\users\kevin.rose\appdata\local\continuum\anaconda2\envs\sdk-v2.2\lib\runpy.py", line 174, in _run_module_as_main
    "__main__", fname, loader, pkg_name)
  File "c:\users\kevin.rose\appdata\local\continuum\anaconda2\envs\sdk-v2.2\lib\runpy.py", line 72, in _run_code
    exec code in run_globals
  File "C:\Users\kevin.rose\AppData\Local\Continuum\Anaconda2\envs\sdk-v2.2\Scripts\tuna.exe\__main__.py", line 9, in <module>
  File "c:\users\kevin.rose\appdata\local\continuum\anaconda2\envs\sdk-v2.2\lib\site-packages\tuna\cli.py", line 13, in main
    start_server(args.infile, args.browser)
  File "c:\users\kevin.rose\appdata\local\continuum\anaconda2\envs\sdk-v2.2\lib\site-packages\tuna\main.py", line 156, in start_server
    data = read(prof_filename)
  File "c:\users\kevin.rose\appdata\local\continuum\anaconda2\envs\sdk-v2.2\lib\site-packages\tuna\main.py", line 22, in read
    return read_import_profile(filename)
  File "c:\users\kevin.rose\appdata\local\continuum\anaconda2\envs\sdk-v2.2\lib\site-packages\tuna\main.py", line 110, in read_import_profile
    line = next(import_lines)
StopIteration

I fixed this with a one-liner updating the read function of main.py to except not only TunaError, but StopIteration as well:

def read(filename):
    _, ext = os.path.splitext(filename)
    try:
        return read_import_profile(filename)
    except (TunaError, StopIteration):
        pass

    # runtime profile
    return read_runtime_profile(filename)

but that was a wild shot in the dark, not sure if the solution would work elsewhere.

Without the stat file, I cannot reproduce the error.

I cannot share the profile file raw unfortunately (don't want to get in trouble w/ legal department), and after a quick couple of minutes trying I cannot get a minimal reproduction.

I can, however, share that there is no newline in the output file that fails. This is why the StopIteration exception is raised (it tries to call next on an iterable with only one element).

I cannot share the profile file raw unfortunately (don't want to get in trouble w/ legal department), and after a quick couple of minutes trying I cannot get a minimal reproduction.

That's too bad. You'll understand that I'm having trouble with an issue I cannot reproduce, and for which I hence cannot verify the fix works.

I'd say let's look at this again once you've managed to produce a more innocuous example.

I appreciate wanting to keep a clean backlog, but I hoped my explanation (no newline so the next call raises the StopIteration exception) was sufficient explanation of the issue. Is there more I can do to elaborate on this?

Alright, fair enough. You've discovered something that doesn't work for you, dug around the code, and found a simple enough fix. I've added your proposed fix now. Hope this works for you!