Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to not restart the server everytime when working with Flask or Express?

I am new on web app development.

My question is ... I have tried some hand-on development on Zend + Apache(php) , Flask(python), Express under node.js.

I found that when I start doing development on Zend framework + Apache, there is no need to restart the apache every time when there is code change in PHP under Controller, Model or Views. It is very convenient and fast!

However, if I work on Flask or Express, I have to restart the whole application everytime when i change code on Controller or Model part. There is no need to restart the server if there is code change on View parts. However, it is annoying enough!!!

Right now, i am working on the project on Flask, how can I avoid the restart the server everytime??? Can the problem be solved if i put the whole web app on top of Nginx??

Thanks a lot

like image 717
TheOneTeam Avatar asked Feb 29 '12 16:02

TheOneTeam


2 Answers

UPDATE:

When debug mode is on for Flask, the server will detect for changes::

from application import app
app.debug = True

if __name__ == '__main__':
    app.run()

However, in production setting, it is not recommended to auto-refresh the server.


Run it on top of tornado:

$ pip install tornado

Create a new file server.py, which wrap up the app.py:

from tornado import autoreload
from tornado.wsgi import WSGIContainer
from tornado.httpserver import HTTPServer
from tornado.ioloop import IOLoop

http_server = HTTPServer(WSGIContainer(app))
http_server.listen(5000)
ioloop = IOLoop.instance()
autoreload.start(ioloop)
ioloop.start()
like image 197
hllau Avatar answered Nov 04 '22 10:11

hllau


If running with mod_wsgi, you just need to change or touch the WSGI script that WSGIScriptAlias points to.

touch /home/user/env/app.wsgi

See http://code.google.com/p/modwsgi/wiki/ReloadingSourceCode

like image 38
jd. Avatar answered Nov 04 '22 11:11

jd.