guides

Health Checks and Graceful Shutdown

Implement liveness, readiness, and graceful termination.

Published May 30, 2026

Liveness Probe

def liveness() -> dict:
    return {'status': 'alive', 'timestamp': time.time()}

Readiness Probe

def readiness() -> dict:
    cache_ok = pathlib.Path('~/.pyvorin/cache').exists()
    return {'ready': cache_ok, 'cache_size': get_cache_size()}

Graceful Shutdown

import signal

def shutdown_handler(signum, frame):
    global running
    running = False
    flush_queues()

signal.signal(signal.SIGTERM, shutdown_handler)
signal.signal(signal.SIGINT, shutdown_handler)

Kubernetes Probes

livenessProbe:
  httpGet:
    path: /health/live
    port: 8080
  periodSeconds: 10
readinessProbe:
  httpGet:
    path: /health/ready
    port: 8080
  periodSeconds: 5