12

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?

4
  • Are you using flask web server in deployment? Commented Jul 22, 2014 at 11:19
  • 3
    To 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/deploying Commented 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). Commented Jul 22, 2014 at 11:24
  • What Daniel said. Don't use the dev server in production. Commented Jul 23, 2014 at 0:40

3 Answers 3

3

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:

http://redbrain.github.io/watchy/

Sign up to request clarification or add additional context in comments.

Comments

3

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.

Comments

0

In my case, I need to change worker_class from 'sync' to 'gevent', since I do some asynchronous tasks. Then no more hangs.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.