Auto Reload
Isn't it a pain to reload your CherryPy server every time you make a change? With the builtin autoreload mechanism, you don't have to; it happens automatically!
By default, all files in sys.modules are checked for changes. If you want to explicitly add additional files, you can append them to the engine.reload_files list.
When you deploy your application, make sure you turn autoreload off. You can do this by setting the config entry "environment" to "production", or you can turn it off explicitly:
[global] engine.autoreload_on = False
If you experience high CPU usage, try setting engine.autoreload_frequency to something higher than the default of 1 second.
Older versions
| replace this | with this | |
| 2.2 | engine.autoreload_on | autoreload.on |
| engine.autoreload_frequency | autoreload.frequency | |
| 2.1 | engine.autoreload_frequency | no equivalent |
2.0
PeterHunt? wrote an AutoReload based off of Python Paste's reloader which works in Python 2.4.
- Download autoreload.py
- Encapsulate the typical code to start CherryPy in a function, then pass that function to 'autoreload.main()', as follows:
from mysite import MySiteRoot def start(): from cherrypy import cpg cpg.root = MySiteRoot() cpg.config.update('tutorial.conf') cpg.server.start() if __name__ == "__main__": import autoreload autoreload.main(start)
- Make sure that application specific imports are outside the start() function. Modules imported inside the start() function will not be checked for changes.
- You can get AutoReload to check other files for changes, not only the python modules you imported. For example, the following will reload CherryPy when a change is made to the configuration file:
import autoreload autoreload.reloadFiles = ["tutorial.conf"] autoreload.main(start)
Attachments
- autoreload.py (5.8 kB) -
Why bother chasing the file. .
, added by anonymous on 11/22/04 14:30:07.

