Python: Automatically restart WSGIServer+Bottle app on file changes

7.1k Views Asked by At

I'm playing with Bottle & Gevent to have an HTTP + WebSockets server. If I were to implement this in Node I'd use Nodemon or similar to restart the server on changes to the code while developing. If I was using just Bottle and the run method I believe I could use run(reloader=True)—however I am running the app using WSGIServer. Given this, how can I have the autoreload functionality I'm after?

http_server = WSGIServer(('127.0.0.1', 8080), app, handler_class=WebSocketHandler)

3

There are 3 best solutions below

1
Jeremy Allen On BEST ANSWER

After searching on pypi I think that server-reloader will do what you ask.

1
ttfreeman On

You don't need an external module. If you set the debug=True, it will reload after every code change. Depending on how you've set up your app, you can do so for instance with app factory:

def create_app(config, debug=True):
   ....

or from command line:

app.run(debug=True)

or

$ export FLASK_DEBUG=1
$ flask run
1
krishnazden On

in your app.py or python file add following lines

app = Flask(__name__)
app.config['DEBUG'] = True