Finding gunicorn worker number inside django app?

39 views
Skip to first unread message

Roy Smith

unread,
Nov 16, 2013, 1:57:37 PM11/16/13
to django...@googlegroups.com
I'm running django (1.4) with gunicorn (0.17.4) and gevent.  I want to have the gunicorn worker number available inside of django, so I can include it in log messages and statsd data for tracking purposes.

What I'm doing right now is I put a pre_request hook in my gunicorn config file which fakes a HTTP header

def pre_request(worker, req):
   req.headers.append(("X-SONGZA-WORKER", str(worker.age)))

This works, but it seems kind of hacky.  It's also messy because I need to process it for every request.  It would be cleaner to do this in post_fork(), but I don't see how to communicate any information from the worker object available in pre_fork() to something that's visible inside django.

Reply all
Reply to author
Forward
0 new messages