Download Install Tutorial Docs FAQ Tools WikiLicense Team IRC Planet Involvement Shop Book

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.2engine.autoreload_on autoreload.on
engine.autoreload_frequencyautoreload.frequency
2.1engine.autoreload_frequencyno equivalent

2.0

PeterHunt? wrote an AutoReload based off of Python Paste's reloader which works in Python 2.4.

  1. Download autoreload.py
  2. 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)
  1. Make sure that application specific imports are outside the start() function. Modules imported inside the start() function will not be checked for changes.
  2. 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

Hosted by WebFaction

Log in as guest/cpguest to create tickets