9

I am using waitress to serve the web application content like.

waitress-serve --port=8000 myapp:application

While developing, as I change code, I continuously had to restart the waitress-serve to see my changes. Is there a standard way I can automate this?

Ashok Bommisetti
  • 314
  • 1
  • 3
  • 15
  • If you are changing python code, then you'll have to restart the server. HTML code will change in the next request – OneCricketeer Apr 23 '16 at 23:28
  • Is your application written with [Flask](http://flask.pocoo.org/snippets/34/)? Then you might want to try [this snippet](http://flask.pocoo.org/snippets/34/), it works for me together with `waitress`. Apart from that, have a look at https://pypi.python.org/pypi/ReloadWSGI and https://github.com/loomchild/reload . I have not tried any of them yet but the description seems to fit the use case. – Dirk Jun 03 '16 at 08:44
  • 1
    @Dirk That snippet you mention....link is broken. – Alex Apr 12 '20 at 09:20

2 Answers2

10

I know this is an old question but I had a similar issue trying to enable hot reload functionality for my REST API using Falcon framework.

Waitress does not monitor file changes but you could use hupper on top of it. Pretty simple:

$ pip install hupper
$ hupper -m waitress --port=8000 myapp:application

It works on Windows too.

AndreFeijo
  • 10,044
  • 7
  • 34
  • 64
4

Based on the comment by @Dirk, I found the archive.org link to the snippet mentioned. I was able to get Waitress reloading by using Werkseug directly. Using Werkzeug's decorator run_with_reloader causes the app to restart whenever a Python file changes. (Werkzeug is used within Flask so it should be available).

Additionally, the app.debug = True line causes Flask to reload template files when they change. So you may want both considering your particular situation.

import werkzeug.serving

@werkzeug.serving.run_with_reloader
def run_server():
    app.debug = True
    waitress.serve(app, listen='127.0.0.1:4432')

if __name__ == '__main__':
    run_server()

Once I had my server set up this way, it auto-reloaded the server whenever any file changed.

Ethan T
  • 1,390
  • 12
  • 28