hupper API¶
- hupper.start_reloader(worker_path, reload_interval=1, shutdown_interval=<default>, verbose=1, logger=None, monitor_factory=None, worker_args=None, worker_kwargs=None, ignore_files=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.IReloaderProxywhich can be used to communicate with the monitor.worker_pathmust 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_reloaderin the first place.reload_intervalis a value in seconds and will be used to throttle restarts. Default is1.shutdown_intervalis a value in seconds and will be used to trigger a graceful shutdown of the server. Set toNoneto disable the graceful shutdown. Default is the same asreload_interval.verbosecontrols the output. Set to0to turn off any logging of activity and turn up to2for extra output. Default is1.logger, if supplied, supersedesverboseand should be an object implementinghupper.interfaces.ILogger.monitor_factoryis an instance ofhupper.interfaces.IFileMonitorFactory. If left unspecified, this will try to create ahupper.watchdog.WatchdogFileMonitorif watchdog is installed and will fallback to the less efficienthupper.polling.PollingFileMonitorotherwise.If
monitor_factoryisNoneit can be overridden by theHUPPER_DEFAULT_MONITORenvironment variable. It should be a dotted python path pointing at an object implementinghupper.interfaces.IFileMonitorFactory.ignore_filesif provided must be an iterable of shell-style patterns to ignore.
- hupper.get_reloader()[source]¶
Get a reference to the current
hupper.interfaces.IReloaderProxy.Raises a
RuntimeErrorif the current process is not actively being monitored by a parent process.
- class hupper.reloader.Reloader(worker_path, monitor_factory, logger, reload_interval=1, shutdown_interval=1, worker_args=None, worker_kwargs=None, ignore_files=None)[source]¶
A wrapper class around a file monitor which will handle changes by restarting a new worker process.
- class hupper.interfaces.IFileMonitorFactory[source]¶
- abstract __call__(callback, **kw)[source]¶
Return an
IFileMonitorinstance.callbackis a callable to be invoked by theIFileMonitorwhen file changes are detected. It should accept the path of the changed file as its only parameter.Extra keyword-only arguments:
intervalis the value ofreload_intervalpassed to the reloader and may be used to control behavior in the file monitor.loggeris anILoggerinstance used to record runtime output.
- __weakref__¶
list of weak references to the object
- class hupper.polling.PollingFileMonitor(callback, interval=1, **kw)[source]¶
An
hupper.interfaces.IFileMonitorthat stats the files at periodic intervals.callbackis a callable that accepts a path to a changed file.intervalis 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.
- class hupper.watchdog.WatchdogFileMonitor(callback, logger, **kw)[source]¶
An
hupper.interfaces.IFileMonitorthat useswatchdogto watch for file changes uses inotify.callbackis a callable that accepts a path to a changed file.loggeris anhupper.interfaces.ILoggerinstance.
- class hupper.watchman.WatchmanFileMonitor(callback, logger, sockpath=None, binpath='watchman', timeout=10.0, **kw)[source]¶
An
hupper.interfaces.IFileMonitorthat uses Facebook’swatchmandaemon to detect changes.callbackis a callable that accepts a path to a changed file.