cherrypy.process.plugins module

Site services for use with a Web Site Process Bus.

class cherrypy.process.plugins.Autoreloader(bus, frequency=1, match='.*')[source]

Bases: cherrypy.process.plugins.Monitor

Monitor which re-executes the process when files change.

This plugin restarts the process (via os.execv()) if any of the files it monitors change (or is deleted). By default, the autoreloader monitors all imported modules; you can add to the set by adding to autoreload.files:


If there are imported files you do not wish to monitor, you can adjust the match attribute, a regular expression. For example, to stop monitoring cherrypy itself:

cherrypy.engine.autoreload.match = r'^(?!cherrypy).+'

Like all Monitor plugins, the autoreload plugin takes a frequency argument. The default is 1 second; that is, the autoreloader will examine files once each second.

static _archive_for_zip_module(module)[source]

Return the archive filename for the module if relevant.

classmethod _file_for_file_module(module)[source]

Return the file for the module.

classmethod _file_for_module(module)[source]

Return the relevant file for the module.

static _make_absolute(filename)[source]

Ensure filename is absolute to avoid effect of os.chdir.

files = None

The set of files to poll for modifications.

frequency = 1

The interval in seconds at which to poll for modified files.

match = '.*'

A regular expression by which to match filenames.


Reload the process if registered files have been modified.


Start our own background task thread for


Return a Set of sys.modules filenames to monitor.

class cherrypy.process.plugins.BackgroundTask(interval, function, args=[], kwargs={}, bus=None)[source]

Bases: threading.Thread

A subclass of threading.Thread whose run() method repeats.

Use this class for most repeating tasks. It uses time.sleep() to wait for each interval, which isn’t very responsive; that is, even if you call self.cancel(), you’ll have to wait until the sleep() call finishes before the thread stops. To compensate, it defaults to being daemonic, which means it won’t delay stopping the whole process.


Method representing the thread’s activity.

You may override this method in a subclass. The standard run() method invokes the callable object passed to the object’s constructor as the target argument, if any, with sequential and keyword arguments taken from the args and kwargs arguments, respectively.

class cherrypy.process.plugins.Daemonizer(bus, stdin='/dev/null', stdout='/dev/null', stderr='/dev/null')[source]

Bases: cherrypy.process.plugins.SimplePlugin

Daemonize the running script.

Use this with a Web Site Process Bus via:


When this component finishes, the process is completely decoupled from the parent environment. Please note that when this component is used, the return code from the parent process will still be 0 if a startup error occurs in the forked children. Errors in the initial daemonizing process still return proper exit codes. Therefore, if you use this plugin to daemonize, don’t use the return code as an accurate indicator of whether the process fully started. In fact, that return code only indicates if the process successfully finished the first fork.

static daemonize(stdin='/dev/null', stdout='/dev/null', stderr='/dev/null', logger=<function Daemonizer.<lambda>>)[source]
class cherrypy.process.plugins.DropPrivileges(bus, umask=None, uid=None, gid=None)[source]

Bases: cherrypy.process.plugins.SimplePlugin

Drop privileges. uid/gid arguments not available on Windows.

Special thanks to Gavin Baker

property gid



The gid under which to run. Availability

property uid



The uid under which to run. Availability

property umask

The default permission mode for newly created files and directories.

Usually expressed in octal format, for example, 0644. Availability: Unix, Windows.

class cherrypy.process.plugins.Monitor(bus, callback, frequency=60, name=None)[source]

Bases: cherrypy.process.plugins.SimplePlugin

WSPBus listener to periodically run a callback in its own thread.

callback = None

The function to call at intervals.

frequency = 60

The time in seconds between callback runs.


Stop the callback’s background task thread and restart it.


Start our callback in its own background thread.


Stop our callback’s background task thread.

thread = None

A BackgroundTask thread.

class cherrypy.process.plugins.PIDFile(bus, pidfile)[source]

Bases: cherrypy.process.plugins.SimplePlugin

Maintain a PID file via a WSPBus.

class cherrypy.process.plugins.PerpetualTimer(*args, **kwargs)[source]

Bases: threading.Timer

A responsive subclass of threading.Timer whose run() method repeats.

Use this timer only when you really need a very interruptible timer; this checks its ‘finished’ condition up to 20 times a second, which can results in pretty high CPU usage


Method representing the thread’s activity.

You may override this method in a subclass. The standard run() method invokes the callable object passed to the object’s constructor as the target argument, if any, with sequential and keyword arguments taken from the args and kwargs arguments, respectively.

class cherrypy.process.plugins.SignalHandler(bus)[source]

Bases: object

Register bus channels (and listeners) for system signals.

You can modify what signals your application listens for, and what it does when it receives signals, by modifying SignalHandler.handlers, a dict of {signal name: callback} pairs. The default set is:

handlers = {'SIGTERM': self.bus.exit,
            'SIGHUP': self.handle_SIGHUP,
            'SIGUSR1': self.bus.graceful,

The SignalHandler.handle_SIGHUP`() method calls bus.restart() if the process is daemonized, but bus.exit() if the process is attached to a TTY. This is because Unix window managers tend to send SIGHUP to terminal windows when the user closes them.

Feel free to add signals which are not available on every platform. The SignalHandler will ignore errors raised from attempting to register handlers for unknown signals.

_handle_signal(signum=None, frame=None)[source]

Python signal handler (self.set_handler subscribes it for you).


Return boolean indicating if the current process is running as a daemon.

The criteria to determine the daemon condition is to verify if the current pid is not the same as the one that got used on the initial construction of the plugin and the stdin is not connected to a terminal.

The sole validation of the tty is not enough when the plugin is executing inside other process like in a CI tool (Buildbot, Jenkins).

_jython_SIGINT_handler(signum=None, frame=None)[source]

Restart if daemonized, else exit.

handlers = {}

A map from signal names (e.g. ‘SIGTERM’) to handlers (e.g. bus.exit).

set_handler(signal, listener=None)[source]

Subscribe a handler for the given signal (number or name).

If the optional ‘listener’ argument is provided, it will be subscribed as a listener for the given signal’s channel.

If the given signal name or number is not available on the current platform, ValueError is raised.

signals = {<Signals.SIGHUP: 1>: 'SIGHUP', <Signals.SIGINT: 2>: 'SIGINT', <Signals.SIGQUIT: 3>: 'SIGQUIT', <Signals.SIGILL: 4>: 'SIGILL', <Signals.SIGTRAP: 5>: 'SIGTRAP', <Signals.SIGABRT: 6>: 'SIGABRT', <Signals.SIGBUS: 7>: 'SIGBUS', <Signals.SIGFPE: 8>: 'SIGFPE', <Signals.SIGKILL: 9>: 'SIGKILL', <Signals.SIGUSR1: 10>: 'SIGUSR1', <Signals.SIGSEGV: 11>: 'SIGSEGV', <Signals.SIGUSR2: 12>: 'SIGUSR2', <Signals.SIGPIPE: 13>: 'SIGPIPE', <Signals.SIGALRM: 14>: 'SIGALRM', <Signals.SIGTERM: 15>: 'SIGTERM', <Signals.SIGCHLD: 17>: 'SIGCHLD', <Signals.SIGCONT: 18>: 'SIGCONT', <Signals.SIGSTOP: 19>: 'SIGSTOP', <Signals.SIGTSTP: 20>: 'SIGTSTP', <Signals.SIGTTIN: 21>: 'SIGTTIN', <Signals.SIGTTOU: 22>: 'SIGTTOU', <Signals.SIGURG: 23>: 'SIGURG', <Signals.SIGXCPU: 24>: 'SIGXCPU', <Signals.SIGXFSZ: 25>: 'SIGXFSZ', <Signals.SIGVTALRM: 26>: 'SIGVTALRM', <Signals.SIGPROF: 27>: 'SIGPROF', <Signals.SIGWINCH: 28>: 'SIGWINCH', <Signals.SIGIO: 29>: 'SIGPOLL', <Signals.SIGPWR: 30>: 'SIGPWR', <Signals.SIGSYS: 31>: 'SIGSYS', <Signals.SIGRTMIN: 34>: 'SIGRTMIN', <Signals.SIGRTMAX: 64>: 'SIGRTMAX'}

A map from signal numbers to names.


Subscribe self.handlers to signals.


Unsubscribe self.handlers from signals.

class cherrypy.process.plugins.SimplePlugin(bus)[source]

Bases: object

Plugin base class which auto-subscribes methods for known channels.

bus = None

A Bus, usually cherrypy.engine.


Register this object as a (multi-channel) listener on the bus.


Unregister this object as a listener on the bus.

class cherrypy.process.plugins.ThreadManager(bus)[source]

Bases: cherrypy.process.plugins.SimplePlugin

Manager for HTTP request threads.

If you have control over thread creation and destruction, publish to the ‘acquire_thread’ and ‘release_thread’ channels (for each thread). This will register/unregister the current thread and publish to ‘start_thread’ and ‘stop_thread’ listeners in the bus as needed.

If threads are created and destroyed by code you do not control (e.g., Apache), then, at the beginning of every HTTP request, publish to ‘acquire_thread’ only. You should not publish to ‘release_thread’ in this case, since you do not know whether the thread will be re-used or not. The bus will call ‘stop_thread’ listeners for you when it stops.


Run ‘start_thread’ listeners for the current thread.

If the current thread has already been seen, any ‘start_thread’ listeners will not be run again.


Release all threads and run all ‘stop_thread’ listeners.


Release the current thread and run ‘stop_thread’ listeners.


Release all threads and run all ‘stop_thread’ listeners.

threads = None

index number} pairs.


A map of {thread ident