Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How can I get Bottle to restart on file change?

I'm really enjoying Bottle so far, but the fact that I have to CTRL+C out of the server and restart it every time I make a code change is a big hit on my productivity. I've thought about using Watchdog to keep track of files changing then restarting the server, but how can I do that when the bottle.run function is blocking.

Running the server from an external script that watches for file changes seems like a lot of work to set up. I'd think this was a universal issue for Bottle, CherryPy and etcetera developers.

Thanks for your solutions to the issue!

like image 848
Hubro Avatar asked Jun 12 '12 20:06

Hubro


People also ask

How do I stop a bottle server?

When starting a bottle webserver without a thread or a subprocess, there's no problem. To exit the bottle app -> CTRL + c .

How do you run a bottle app?

Bottle framework learning checklistDownload Bottle or install via pip with pip install bottle on your local development machine. Work through the official Bottle tutorial. Start coding your Bottle app based on what you learned in the official tutorial plus reading open source example applications found above.


2 Answers

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 run run(reloader=True) 
like image 61
Mark Hildreth Avatar answered Oct 05 '22 23:10

Mark Hildreth


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.

like image 26
f p Avatar answered Oct 06 '22 00:10

f p