Subsections

6. How to use the hotReload feature of CherryPy

6.1 Introduction

The development cycle of a CherryPy web site is the same as the development cycle of a regular software:

The compilation process is usually pretty fast (if you have a "decent" computer).

But what if the CherryPy server has a long initialization process (maybe it needs to connect to several ressources, like databases, or it needs to precompute some data). All this work is usually done in the initServer special function. If this initialization takes a lot of time, having to stop and restart the server everytime you make a change is really a loss of time while developing your web site.

This is where the hotReload feature comes in. It allows you to refresh your code without having to stop the server.

6.2 How does it work ?

When it receives a hotReload request, the server will just read its source code again, updating all the CherryClasses code and recreating new CherryClasses instances with the new code. It will not execute initServer again. Instead, it will execute hotReloadInitServer if any.

6.3 How to use it ?

The hotReload feature is enabled in the executable when the file is compiled with the -D flag (debug mode).

To send a hotReload request to a running CherryPy server, just use the little script called cherryhotreload.py provided with the distribution.

Let's take a practical example that shows how to use the hotReload feature:

Warning: After a hotReload, the line numbers that the python interpreter might give you in case of an error may not match your source file. This happens if you add or remove lines of code before the hotReload

See About this document... for information on suggesting changes.