How can I get Bottle to restart on file change? How can I get Bottle to restart on file change? python python

How can I get Bottle to restart on file change?


Check out from the tutorial a section entitled "Auto Reloading"

During development, you have to restart the server a lot to test your recent changes. The auto reloader can do this for you. Every time you edit a module file, the reloader restarts the server process and loads the newest version of your code.

This gives the following example:

from bottle import runrun(reloader=True)


With

run(reloader=True)

there are situations where it does not reload like when the import is inside a def. To force a reload I used

subprocess.call(['touch', 'mainpgm.py'])

and it reloads fine in linux.


Use reloader=True in run(). Keep in mind that in windows this must be under if __name__ == "__main__": due to the way the multiprocessing module works.

from bottle import runif __name__ == "__main__":    run(reloader=True)