Circus Process & Socket Manager

0.19.0 · active · verified Thu Apr 16

Circus is a robust Python program designed to run, monitor, and manage multiple processes and sockets. It provides a flexible way to supervise long-running services, akin to tools like Supervisor, but with a focus on programmatic control and extensibility. The current version is 0.19.0. Releases are somewhat irregular, often tied to Python version support or dependency updates.

Common errors

Warnings

Install

Imports

Quickstart

This quickstart demonstrates how to programmatically define a watcher for a simple Python script and manage it using the Circus Arbiter. Run this script, and it will start a child process that prints messages every 2 seconds until the Arbiter is stopped via Ctrl+C.

from circus.watcher import Watcher
from circus.arbiter import Arbiter
import time
import sys

# Define a simple command to run
# Using sys.executable ensures the current Python environment's interpreter is used.
command = f"{sys.executable} -c \"import time; print('Hello from Circus!'); time.sleep(2); print('Process exiting.')\""

# Create a watcher for our process
# 'stop_signal' 15 (SIGTERM) is a common graceful shutdown signal
watcher = Watcher(name="my_test_process", cmd=command, numprocesses=1, stop_signal=15)

# Create an arbiter and register the watcher
arbiter = Arbiter([watcher])

print("Starting Circus Arbiter...")
try:
    # Start the arbiter, which will launch and manage the watcher's processes
    arbiter.start()
    print("Arbiter started. Processes are running. Press Ctrl+C to stop.")
    # Keep the main thread alive to allow the arbiter to run in the background
    while True:
        time.sleep(1)
except KeyboardInterrupt:
    print("\nCtrl+C detected. Stopping Arbiter...")
    # Cleanly stop the arbiter and its managed processes
    arbiter.stop()
    print("Arbiter stopped. Exiting.")
except Exception as e:
    print(f"An error occurred: {e}")
    arbiter.stop()
    sys.exit(1)

view raw JSON →