Flask development server hot-reload gets stuck reloading

Viewed 53

I'm hoping to get auto-reload functioning properly. To do so, I'm running my flask app with

FLASK_ENV="development" FLASK_DEBUG=1 flask run

Which starts the server in development mode as expected. However, when I make a change, the hot reload begins (as expected) ... and then never ends. I.e. I see the following:

Starting application.py ...
 * Detected change in '/Users/allen/path/to/edited/file.py', reloading

I'm running the flask app from a pyenv virtual environment that is generated using the following makefile command:

    @ #check that the python version is equal to 3.9.10 and if not echo the message and exit
    python3 --version | grep -q "Python 3.9.10" || (echo "Python version is not equal to 3.9.10" && exit 1)

    @ # check that the pip version is greater than 21.0.0 and if not echo the message and exit
    pip3 --version | grep -q "pip 22." || (echo "pip version is not 22.x.x" && exit 1)
    
    # install pipx 
    pip3 install --no-cache-dir pipx 

    # install pipenv and sync dependencies  
    pipx install pipenv
    pipx ensurepath
    PIPENV_VENV_IN_PROJECT=1
    export $(cat .env | xargs) && pipenv sync --python 3.9.10
    pipenv shell
    python secrets/secrets_manager.py --write-to-file True

I'm at a bit of a loss as to how to debug from here since I don't have any visibility into what's going on under the hood in the Werkzeug reloader's child process, so any pointers as to how to do so (or ideas on how to solve this issue directly) greatly appreciated. The only thing I was able to infer was that the Werkzeug subprocess has its main thread killed when the hot reload happens, but child threads are left alive, and the main thread never re-instantiates. Running the debugger with the 'subprocess-false' flag (VScode) doesn't reproduce this particular behavior but still gets frozen in the same way.

Happy to provide more details as it is helpful. I likely can't copy-paste all the code here (it's a fairly large and not public project), but I can hopefully put any relevant pieces. Thanks!

0 Answers
Related