I am running a flask web server, it works fine during testing, but now freezes at least once per day. All I need to do is to restart it and it will work again. Is there a good way to monitor it and maybe I should just kill/restart it every time it fails. Do people actually kill their web server periodically to avoid this kind thing from happening?
-
Are you using flask web server in deployment?Bartosz Marcinkowski– Bartosz Marcinkowski2014-07-22 11:19:40 +00:00Commented Jul 22, 2014 at 11:19
-
3To expand Bartosz' question: The default webserver that comes built in with flask is for development only - it's not suitable for production. To deploy flask apps, you need a better WSGI server. See the docs: flask.pocoo.org/docs/deployingDaniel– Daniel2014-07-22 11:23:37 +00:00Commented Jul 22, 2014 at 11:23
-
it is my flask web application. I basically start it and leave it running. I am not using anything else (ngix, apache).Yifan Zhang– Yifan Zhang2014-07-22 11:24:53 +00:00Commented Jul 22, 2014 at 11:24
-
What Daniel said. Don't use the dev server in production.Rachel Sanders– Rachel Sanders2014-07-23 00:40:09 +00:00Commented Jul 23, 2014 at 0:40
3 Answers
If you are using the default Flask webserver: Don't. It's intended for development ONLY.
As additional resource it's worth reading these two blog posts about deploying a Flask application:
http://blog.miguelgrinberg.com/post/the-flask-mega-tutorial-part-xvii-deployment-on-linux-even-on-the-raspberry-pi http://blog.miguelgrinberg.com/post/the-flask-mega-tutorial-part-xviii-deployment-on-the-heroku-cloud
And for monitoring processes in your webserver, you could give Watchy a try:
Comments
While the default web server might not be the best for production, it is probably not the root cause of the crashes. I use it in a production environment on an internal network and it is very stable. Before blaming the web server check to make sure your code can handle requests that that may collide with each other. In my case I had lots of stability issues before I instituted locking on data base tables so that certain requests would be blocked until previous requests were done with updates. Flask can't make sure your code is thread safe. And changing the web server won't help if it is not.