Skip to content

Instantly share code, notes, and snippets.

@hynek
hynek / gunicorn_callbacks_for_worker_id.py
Last active October 24, 2024 13:27
This is an attempt to emulate uWSGI’s uwsgi.worker_id() that ensures that I have worker IDs from 1…--workers which is useful in logging and instrumentation where changing PIDs are annoying.
import os
def on_starting(server):
"""
Attach a set of IDs that can be temporarily re-used.
Used on reloads when each worker exists twice.
"""
server._worker_id_overload = set()