Skip to content
Discussion options

You must be logged in to vote

These are three separate issues that unfortunately all hit at once. Here are the explanations and workarounds:

Issue 1: worker.nr always 0

This is a Gunicorn 24.x regression/change, not a Uvicorn bug. In Gunicorn 24+, worker.nr was changed to only be set correctly for SyncWorker and GeventWorker. For custom worker classes (which UvicornWorker is), nr defaults to 0.

Workaround — assign GPU index based on spawn order using a shared counter:

# gunicorn_config.py
import os
import multiprocessing

_worker_counter = multiprocessing.Value('i', 0)

def post_fork(server, worker):
    with _worker_counter.get_lock():
        idx = _worker_counter.value
        _worker_counter.value += 1
    os.environ

Replies: 1 comment

Comment options

You must be logged in to vote
0 replies
Answer selected by KaHuier
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants