hupper
API¶
- hupper.start_reloader(worker_path, reload_interval=1, verbose=1, monitor_factory=None, worker_args=None, worker_kwargs=None)[source]¶
Start a monitor and then fork a worker process which starts by executing the importable function at
worker_path
.If this function is called from a worker process that is already being monitored then it will return a reference to the current
hupper.interfaces.IReloaderProxy
which can be used to communicate with the monitor.worker_path
must be a dotted string pointing to a globally importable function that will be executed to start the worker. An example could bemyapp.cli.main
. In most cases it will point at the same function that is invokingstart_reloader
in the first place.reload_interval
is a value in seconds and will be used to throttle restarts.verbose
controls the output. Set to0
to turn off any logging of activity and turn up to2
for extra output.monitor_factory
is an instance ofhupper.interfaces.IFileMonitorFactory
. If left unspecified, this will try to create ahupper.watchdog.WatchdogFileMonitor
if watchdog is installed and will fallback to the less efficienthupper.polling.PollingFileMonitor
otherwise.
- hupper.get_reloader()[source]¶
Get a reference to the current
hupper.interfaces.IReloaderProxy
.Raises a
RuntimeError
if the current process is not actively being monitored by a parent process.
- class hupper.reloader.Reloader(worker_path, monitor_factory, reload_interval=1, verbose=1, worker_args=None, worker_kwargs=None)[source]¶
A wrapper class around a file monitor which will handle changes by restarting a new worker process.
- class hupper.interfaces.IFileMonitorFactory[source]¶
- __call__(callback)[source]¶
Return an
IFileMonitor
instance.callback
is a callable to be invoked by theIFileMonitor
when file changes are detected. It should accept the path of the changed file as its only parameter.
- class hupper.polling.PollingFileMonitor(callback, poll_interval=1)[source]¶
An
hupper.interfaces.IFileMonitor
that stats the files at periodic intervals.callback
is a callable that accepts a path to a changed file.poll_interval
is a value in seconds between scans of the files on disk. Do not set this too low or it will eat your CPU and kill your drive.- run()[source]¶
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 hupper.watchdog.WatchdogFileMonitor(callback)[source]¶
An
hupper.interfaces.IFileMonitor
that useswatchdog
to watch for file changes uses inotify.callback
is a callable that accepts a path to a changed file.