alexmojaki / heartrate

Simple real time visualisation of the execution of a Python program.
MIT License
1.76k stars 123 forks source link

KeyError thread_ident #14

Closed pawamoy closed 10 months ago

pawamoy commented 10 months ago

Just running import heartrate; heartrate.trace(browser=True) in an interactive interpreter produces many errors like the following:

[2023-10-27 00:28:02,724] ERROR in app: Exception on /table/ [GET]
Traceback (most recent call last):
  File "/media/data/dev/griffe/__pypackages__/3.11/lib/flask/app.py", line 1455, in wsgi_app
    response = self.full_dispatch_request()
               ^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/media/data/dev/griffe/__pypackages__/3.11/lib/flask/app.py", line 869, in full_dispatch_request
    rv = self.handle_user_exception(e)
         ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/media/data/dev/griffe/__pypackages__/3.11/lib/flask/app.py", line 867, in full_dispatch_request
    rv = self.dispatch_request()
         ^^^^^^^^^^^^^^^^^^^^^^^
  File "/media/data/dev/griffe/__pypackages__/3.11/lib/flask/app.py", line 852, in dispatch_request
    return self.ensure_sync(self.view_functions[rule.endpoint])(**view_args)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/media/data/dev/griffe/__pypackages__/3.11/lib/heartrate/core.py", line 148, in file_table_view
    return render_template('file_table.html', **file_table_context())
                                                ^^^^^^^^^^^^^^^^^^^^
  File "/media/data/dev/griffe/__pypackages__/3.11/lib/heartrate/core.py", line 104, in file_table_context
    highlighted = highlight_ranges(source, frames_matching(filename))
                  ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/media/data/dev/griffe/__pypackages__/3.11/lib/heartrate/core.py", line 226, in highlight_ranges
    for frame in frames:
  File "/media/data/dev/griffe/__pypackages__/3.11/lib/heartrate/core.py", line 154, in frames_matching
    frame = current_frame()
            ^^^^^^^^^^^^^^^
  File "/media/data/dev/griffe/__pypackages__/3.11/lib/heartrate/core.py", line 151, in current_frame
    return sys._current_frames()[thread_ident]
           ~~~~~~~~~~~~~~~~~~~~~^^^^^^^^^^^^^^
KeyError: 140645325195072
alexmojaki commented 10 months ago

I don't think there's a way to make heartrate work in an interactive interpreter, I don't even think it would make sense.

pawamoy commented 10 months ago

Oh, OK, fair enough, I wanted to try it directly in the interpreter. If that's not supported I'll try it by adding a few lines to my entrypoint :slightly_smiling_face: Thanks!