Skip to content

Instantly share code, notes, and snippets.

@tomj74
tomj74 / gunicorn_callbacks_for_worker_id.py
Created August 14, 2019 00:06 — forked from hynek/gunicorn_callbacks_for_worker_id.py
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()