paste.reloader – Monitor for file changes to restart the process

A file monitor and server restarter.

Use this like:

..code-block:: Python

import reloader reloader.install()

Then make sure your server is installed with a shell script like:

while test "$err" -eq 3 ; do

or is run from this .bat file (if you use Windows):

@echo off
if %errorlevel% == 3 goto repeat

or run a monitoring process in Python (paster serve --reload does this).

Use the watch_file(filename) function to cause a reload/restart for other other non-Python files (e.g., configuration files). If you have a dynamic set of files that grows over time you can use something like:

def watch_config_files():
    return CONFIG_FILE_CACHE.keys()

Then every time the reloader polls files it will call watch_config_files and check all the filenames it returns.

Module Contents


Install the reloading monitor.

On some platforms server threads may not terminate when the main thread does, causing ports to remain open/locked. The raise_keyboard_interrupt option creates a unignorable signal which causes the whole application to shut-down (rudely).

class paste.reloader.Monitor(poll_interval)
paste.reloader.watch_file(func, obj, type)