2

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 :)

davidism
  • 121,510
  • 29
  • 395
  • 339
s_om
  • 661
  • 2
  • 9
  • 24
  • I am facing the same issue, reason why i read your question before I add mine. How is your app.py file named? – ReinholdN Jan 15 '20 at 04:48
  • May I ask will this work if you visit a secure domain/hostname rather than an http:// IP address? – pee2pee Jul 07 '22 at 08:47

2 Answers2

1

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

-1

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

Alias_Knagg
  • 886
  • 1
  • 7
  • 21