Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Python: Automatically restart WSGIServer+Bottle app on file changes

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)

like image 299
james_womack Avatar asked Jul 12 '14 00:07

james_womack


3 Answers

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
like image 161
ttfreeman Avatar answered Nov 13 '22 09:11

ttfreeman


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

like image 27
Jeremy Allen Avatar answered Nov 13 '22 11:11

Jeremy Allen


in your app.py or python file add following lines

app = Flask(__name__)
app.config['DEBUG'] = True
like image 1
krishnazden Avatar answered Nov 13 '22 09:11

krishnazden