简体   繁体   中英

Use waitress as a production server for Flask

I have written an application in Python/Flask which I need to deploy in production on a Windows Server(unfortunately). I came across a suggestion to use Waitress. It was a simple modification to make the web app use waitress, but my issues remain unsolved.

To server using waitress I have modified the code as below(just a basic example)

from flask import Flask
from waitress import serve
app = Flask(__name__)

@app.route('/')
def hello():
    return 'Hello World!'

if __name__ == '__main__':
    # app.run()
    serve(app, host='0.0.0.0', port=8000)

Now I can run this from the command prompt via(same as without waitress)

python myapp.py

But I cannot use this in production.

  • How do I make sure that the server keeps running in case someone closes the cmd prompt.
  • How to make sure when the server is rebooted, the webapp comes up automatically without a user having to login and launch the app again.

If these two basic issues are not solvable then I wonder why waitress claims to be a production ready server:)

Waitress isn't responsible to init your server. It's just a way to activate WSGI

To init the service after restart just add to windows startup programs. Validate the server is up there are few ways to do so,the simple running a shell script that check the if the process up and execute it if not

I have just posted a answer to my own similar question here .
I think you will find that it answers this question too:-)

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM