alexmojaki / heartrate

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

No such file or directory: '<frozen importlib._bootstrap>' #2

Closed mendelmaleh closed 4 years ago

mendelmaleh commented 4 years ago

Tried using this with my project, with venv, installed with pip install heartrate, this is the error I get:

$ python main.py
 * Serving Flask app "heartrate.core" (lazy loading)
 * Environment: production
   WARNING: This is a development server. Do not use it in a production deployment.
   Use a production WSGI server instead.
 * Debug mode: on
Traceback (most recent call last):
  File "main.py", line 5, in <module>
    Client('userbot-async', plugins=plugins).run()
  File "/home/mendel/python/userbot/venv/lib/python3.7/site-packages/pyrogram/client/client.py", line 220, in __init__
    super().__init__()
  File "/home/mendel/python/userbot/venv/lib/python3.7/site-packages/pyrogram/client/ext/base_client.py", line 103, in __init__
    self.media_sessions_lock = asyncio.Lock()
  File "/usr/lib/python3.7/asyncio/locks.py", line 161, in __init__
    self._loop = events.get_event_loop()
  File "/usr/lib/python3.7/asyncio/events.py", line 726, in get_event_loop_policy
    _init_event_loop_policy()
  File "/usr/lib/python3.7/asyncio/events.py", line 719, in _init_event_loop_policy
    from . import DefaultEventLoopPolicy
  File "<frozen importlib._bootstrap>", line 416, in parent
  File "/home/mendel/python/userbot/venv/lib/python3.7/site-packages/heartrate/core.py", line 143, in trace_func
    if include_file(filename):
  File "/home/mendel/python/userbot/venv/lib/python3.7/site-packages/heartrate/core.py", line 57, in include_file
    return path == calling_file or files(path)
  File "/home/mendel/python/userbot/venv/lib/python3.7/site-packages/heartrate/files.py", line 18, in func
    with open(path) as f:
FileNotFoundError: [Errno 2] No such file or directory: '<frozen importlib._bootstrap>'

This is the stacktrace in the browser window:

/usr/lib/python3.7/threading.py : 1308 : _shutdown
    lock.acquire()

My code can be found here, I just added import heartrate; heartrate.trace(browser=True) in main.py, line 2.

alexmojaki commented 4 years ago

Whoops, I had some unreleased code. Upgrade and try again.

mendelmaleh commented 4 years ago

Upgraded and it works, thanks. There are another two issues tho:

  1. my program uses trl+c to shutdown, i guess flask too uses that so now its broken
  2. i had to shut it down with ctrl+z instead, and when i started it up again it gave
    File "/usr/lib/python3.7/socketserver.py", line 466, in server_bind
    self.socket.bind(self.server_address)
    OSError: [Errno 98] Address already in use
alexmojaki commented 4 years ago

Both flask and your program should respond to ctrl+c and shut down, although you may need to press it a few times. What exactly happens when you press ctrl+c?

Ctrl+z doesn't shut down, it suspends. So the old process wasn't dead. If nothing else works you will need to find the process ID and kill (maybe kill -9) it.

mendelmaleh commented 4 years ago

So, after the first ctrl+c it shows this in the stacktrace:

/usr/lib/python3.7/threading.py : 1308 : _shutdown
            lock.acquire()

In the terminal it it just shows '^C' (normal), no output from python. The program does stop working, however heartrate still works (can still be reloaded at least).

Doing ctrl+c multiple times doesn't do anything.

alexmojaki commented 4 years ago

I reproduced this, but I couldn't figure out why it doesn't respond to Ctrl+C. Maybe something to do with asyncio?

I added https://github.com/alexmojaki/heartrate/commit/cf9496df5080a3ce9928939d78a55928ea0d3491 as a workaround. Upgrade and use trace(daemon=True) and the server will shutdown when the program ends (e.g. when you press Ctrl+C).