hupper

1.12.1 · active · verified Fri Apr 10

hupper is an integrated process monitor for your Python process, designed for development. It automatically tracks changes to imported Python files and custom paths, restarting the process when files are modified. Reloads can also be triggered manually from code. It is currently at version 1.12.1 and maintains an active release cadence.

Warnings

Install

Imports

Quickstart

To use hupper, define your application's entry point as a callable function. Call `hupper.start_reloader()` from your main script, passing the dotted path to this entry point. `hupper` will then fork a worker process to run your application and monitor for file changes. If changes are detected, the worker process will be restarted. The `HUPPER_RELOADER` environment variable distinguishes between the monitor and worker processes internally. Running the script and then modifying `my_app.py` will demonstrate the reload functionality.

import hupper
import os
import datetime
import time

def worker_func():
    """This function contains the main application logic, re-executed on reload."""
    now = datetime.datetime.now()
    print(f"Worker process active at {now}. Edit 'my_app.py' to trigger reload.")
    # In a real application, this would be your main application loop
    # (e.g., a web server, a background task). For this example, we just
    # sleep briefly to demonstrate the worker's lifecycle.
    try:
        while True:
            time.sleep(1)
    except KeyboardInterrupt:
        print("Worker received KeyboardInterrupt, shutting down.")

def main():
    if os.environ.get('HUPPER_RELOADER') != 'true':
        # This code runs in the *monitor* process
        print("Monitor: Starting reloader for 'my_app.worker_func'...")
        # The first call to start_reloader from the main process
        # forks a worker, starts monitoring, and never returns in this process.
        reloader = hupper.start_reloader('my_app.worker_func')
        # Optional: Watch additional files/directories
        # reloader.watch_files(['./config.ini'])
        print("Monitor: Reloader stopped.") # This line is usually not reached
    else:
        # This code runs in the *worker* process, after being forked by the monitor
        print("Worker: This is a reloaded worker process.")
        worker_func()

if __name__ == '__main__':
    main()

view raw JSON →