Search code examples
pythonwebservergunicornworker

Get worker id from Gunicorn worker itself


I run multiple gunicorn workers with workers=4 setting. So as I understand I have 5 different processes: one gunicorn master process and 4 other worker processes. Can I get information about which worker is serving request at the moment? So can I get any worker id from inside worker itself like for each request send back a response with content: this request was served by worker:worker_id?


Solution

  • 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)