5

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)

james_womack
  • 10,028
  • 6
  • 55
  • 74

3 Answers3

4

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
ttfreeman
  • 5,076
  • 4
  • 26
  • 33
3

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

Jeremy Allen
  • 6,434
  • 2
  • 26
  • 31
  • I will check this out. I'd hoped there'd be some flag I could pass to the server itself. In this case, I might just use nodemon or similar and have it monitor the Python files (e.g. `nodemon --exec "python -v" ./app.py`). That will have the added benefit of monitoring other assets as desired (`nodemon --watch app --watch libs --exec "python -v" ./app.py`). – james_womack Jul 12 '14 at 16:21
0

in your app.py or python file add following lines

app = Flask(__name__)
app.config['DEBUG'] = True
krishnazden
  • 1,127
  • 10
  • 19