Get worker id from Gunicorn worker itself

For debugging purpose, you may use post_request hook to log the worker pid

def post_response(worker, req, environ, resp):
    worker.log.debug("%s", worker.pid)

Within a worker code just use

import os
print(os.getpid())

Process id is a good enough identifier for such a case. Another option which is overkill obviously is to create a worker-id-file for each worker at this point https://docs.gunicorn.org/en/stable/settings.html?highlight=hooks#post-worker-init and read from it when needed. Do not forget to remove this file on exit https://docs.gunicorn.org/en/stable/settings.html?highlight=hooks#worker-exit