Hello, starting up a flask app is easy, but shutting it down or check whether it is still running is hard without having a pid, because in the process list each app is just running with the process name "python2.7". I was trying to get the pid by the typical way of starting it with python2.7 runserver.py & echo $! > pidfile But for some reason the actual pid is one number higher than the value in $! - does python fork to run flask? So how do I get the pid then? The flask.run()-function resp. the underlying werkzeug.run_simple() function doesn't have a pidfile option. How is flask supposed to be shutdown correctly? Does it shutdown gracefully when it receives a kill signal, or will it process pending requests correctly and shutdown then? Kind regards Marten
The Flask/Werkzeug server is just meant for development - you normally just start it in a terminal window. I can't see why you would need anything more complicated. For production you have mod_wsgi, gunicorn, and other WSGI solutions which are more suitable for running a Flask app as a background process (or processes). On 16 November 2010 12:40, Marten Lehmann <lehmann@cnm.de> wrote: > Hello, > > starting up a flask app is easy, but shutting it down or check whether > it is still running is hard without having a pid, because in the process > list each app is just running with the process name "python2.7". > > I was trying to get the pid by the typical way of starting it with > > python2.7 runserver.py & > echo $! > pidfile > > But for some reason the actual pid is one number higher than the value > in $! - does python fork to run flask? > > So how do I get the pid then? The flask.run()-function resp. the > underlying werkzeug.run_simple() function doesn't have a pidfile option. > > How is flask supposed to be shutdown correctly? Does it shutdown > gracefully when it receives a kill signal, or will it process pending > requests correctly and shutdown then? > > Kind regards > Marten >
Hi, > The Flask/Werkzeug server is just meant for development - you normally > just start it in a terminal window. I can't see why you would need > anything more complicated. but even in the terminal it is not clear to me, how can I shutdown the server without possibly interrupting a pending tasks just in the middle of its execution. Just image a user loads a site with a long list and just in the middle I'm quitting flask with Ctrl+C in the terminal window, so the user gets a broken page and an error message. Doesn't look very professional to me. Kind regards Marten
On 17 November 2010 14:59, Marten Lehmann <lehmann@cnm.de> wrote: > Hi, > >> The Flask/Werkzeug server is just meant for development - you normally >> just start it in a terminal window. I can't see why you would need >> anything more complicated. > > but even in the terminal it is not clear to me, how can I shutdown the > server without possibly interrupting a pending tasks just in the middle > of its execution. Just image a user loads a site with a long list and > just in the middle I'm quitting flask with Ctrl+C in the terminal > window, so the user gets a broken page and an error message. Doesn't > look very professional to me. Um, why would it need to ? It's a DEVELOPMENT server. It's not meant for production. For production you use a WSGI server such as Apache/mod_wsgi. > > Kind regards > Marten >
Hello, > Um, why would it need to ? It's a DEVELOPMENT server. It's not meant > for production. > > For production you use a WSGI server such as Apache/mod_wsgi. maybe I'm getting something wrong, but as far as I know, flask is running in a python process. It accepts queries by HTTP, WSGI and FastCGI, by TCP/IP or UNIX Socket. Now you typically put a nginx or Apache with mod_wsgi in front of it for logging, access control etc., talking to flask via HTTP, WSGI or FastCGI. Now at some point, you have to restart or shutdown Flask, may it be for restarting the whole server or just for a newer release of your web application. This is completely independend from any handlers like HTTP or WSGI. There needs to be a way to tell the flask app to shutdown as soon as all pending requests are processed and no new requests shall be accepted for that time. So you can either kill it by a process signal (e.g. kill -TERM) or by a special shutdown function, which is available in different database servers. What is the common practise for flask? Kind regards Marten
> maybe I'm getting something wrong, but as far as I know, flask is > running in a python process. It accepts queries by HTTP, WSGI and > FastCGI, by TCP/IP or UNIX Socket. Now you typically put a nginx or > Apache with mod_wsgi in front of it for logging, access control etc., > talking to flask via HTTP, WSGI or FastCGI. > > Now at some point, you have to restart or shutdown Flask, may it be for > restarting the whole server or just for a newer release of your web > application. This is completely independend from any handlers like HTTP > or WSGI. There needs to be a way to tell the flask app to shutdown as > soon as all pending requests are processed and no new requests shall be > accepted for that time. So you can either kill it by a process signal > (e.g. kill -TERM) or by a special shutdown function, which is available > in different database servers. What is the common practise for flask? It depends on the WSGI handler. In the case of mod_wsgi (for example) you restart the processes by touching the .wsgi file or restarting Apache. You don't "shut down or restart Flask". Flask has a simple WSGI server for running in development. I repeat again that it is not meant for production. You run it in your terminal and access it through localhost in your browser. It should never, ever be used in a production setting. It exists purely as a convenience when building Flask apps. Django has the same thing (manage.py runserver), and again, you don't run the Django development server in production. When you run a Flask app in production, or any other WSGI app for that matter - Django, Pylons, etc - you deploy it according to whatever WSGI container you are using. To take again the example of Apache/mod_wsgi you create a .wsgi file with whatever settings, import your Flask app, and point your mod_wsgi settings at this .wsgi file. I would strongly suggest you read the WSGI spec carefully and instructions for mod_wsgi or whatever container you wish to use. > > Kind regards > Marten >
I agree, I don't see the context in why would you like to use the Flask server in that way. 2010/11/17 danjac354@gmail.com <danjac354@gmail.com> > On 17 November 2010 14:59, Marten Lehmann <lehmann@cnm.de> wrote: > > Hi, > > > >> The Flask/Werkzeug server is just meant for development - you normally > >> just start it in a terminal window. I can't see why you would need > >> anything more complicated. > > > > but even in the terminal it is not clear to me, how can I shutdown the > > server without possibly interrupting a pending tasks just in the middle > > of its execution. Just image a user loads a site with a long list and > > just in the middle I'm quitting flask with Ctrl+C in the terminal > > window, so the user gets a broken page and an error message. Doesn't > > look very professional to me. > > Um, why would it need to ? It's a DEVELOPMENT server. It's not meant > for production. > > For production you use a WSGI server such as Apache/mod_wsgi. > > > > > Kind regards > > Marten > > > -- Rodrigo Aliste P.