问题
I am on Windows, using python 2.7, flask installed with pip. I am trying to get flask reload my python module after source code change. I did
SET FLASK_APP=backend.py
set FLASK_DEBUG=1
flask run
this causes the following error:
* Serving Flask app "backend"
* Forcing debug mode on
* Restarting with stat
c:\python27\python.exe: can't open file 'C:\Python27\Scripts\flask': [Errno 2] No such file or directory
So I tried (as suggested by some others)
python -m flask run
which however caused the following error:
* Serving Flask app "backend"
* Forcing debug mode on
* Restarting with stat
* Debugger is active!
* Debugger pin code: 168-045-575
* Debugger is active!
* Debugger pin code: 243-777-971
* Running on http://127.0.0.1:5000/ (Press CTRL+C to quit)
127.0.0.1 - - [08/Jan/2017 15:22:29] "GET / HTTP/1.1" 500 -
Traceback (most recent call last):
File "D:\Projects\MyWebApp\backend.py", line 21, in <module>
app.run()
File "C:\Python27\lib\site-packages\flask\app.py", line 843, in run
run_simple(host, port, self, **options)
File "C:\Python27\lib\site-packages\werkzeug\serving.py", line 692, in run_simple
reloader_type)
File "C:\Python27\lib\site-packages\werkzeug\_reloader.py", line 242, in run_with_reloader
signal.signal(signal.SIGTERM, lambda *args: sys.exit(0))
ValueError: signal only works in main thread
How can I get flask to run with automatic re-loader on Windows?
回答1:
Fixed in werkzeug 0.11.13 as mentioned by snakecharmerb. After
pip install werkzeug --upgrade
reload is working as expected.
来源:https://stackoverflow.com/questions/41532654/flask-reload-module-on-windows