I am looking for something like uWSGI + django autoreload mode for Flask.
相关问题
- Plain (non-HTML) error pages in REST api
- WTForms form with custom validate method is never
- flask application with watchdog observer
- Why is `node.js` dying when called from inside pyt
- How to deploy python flask application in conda ba
相关文章
- 请问为什么后台获取不到表单数据
- TypeError: 'BaseQuery' object is not calla
- How do I send cookies with request when testing Fl
- unable to load configuration from uwsgi
- Angular route not working when used with Google Ap
- SQLAlchemy - Is there a way to see what is current
- What is uWSGI master mode?
- POST csv/Text file using cURL
The auto-reloading functionality of development-mode Flask is actually provided by the underlying Werkzeug library. The relevant code is in
werkzeug/serving.py
-- it's worth taking a look at. But basically, the main application spawns the WSGI server as a subprocess that stats every active.py
file once per second, looking for changes. If it sees any, the subprocess exits, and the parent process starts it back up again -- in effect reloading the chages.There's no reason you couldn't implement a similar technique at the layer of uWSGI. If you don't want to use a stat loop, you can try using underlying OS file-watch commands. Apparently (according to Werkzeug's code), pyinotify is buggy, but perhaps Watchdog works? Try a few things out and see what happens.
Edit:
In response to the comment, I think this would be pretty easy to reimplement. Building on the example provided from your link, along with the code from
werkzeug/serving.py
:It's untested, but should work.
If you're configuring
uwsgi
with command arguments, pass--py-autoreload=1
:If you're using a
.ini
file to configureuwsgi
and usinguwsgi --ini
, add the following to your.ini
file:I am running uwsgi version 1.9.5 and the option
works great
For development environment you can try using --python-autoreload uwsgi's parameter. Looking at the source code it may work only in threaded mode (--enable-threads).
(You can use an arbitrary WSGI server)
I am afraid that Flask is really too bare bones to have an implementation like this bundled by default.
Dynamically reloading code in production is generally a bad thing, but if you are concerned about a dev environment, take a look at this bash shell script http://aplawrence.com/Unixart/watchdir.html
Just change the sleep interval to whatever suits your needs and substitute the echo command with whatever you use to reload uwsgi. I run uwsgi un master mode and just send a killall uwsgi command.