[uWSGI] worker initialization

Roberto De Ioris roberto at unbit.it
Wed Oct 13 07:11:19 CEST 2010

> Hello,
> I am using uwsgi with a django application behind nginx. I 'd like to
> introduce some initialization logic just after workers spawning but before
> actual django app's loading. Eg. i 'd like to set some env variables which
> names contains the workers' pid or even pre-initialize each
> worker/django's
> logging facilities. I have read about 'uwsgi.workers()' but their pids are
> (of course) 0 when -w module is loaded while i can't find any hook between
> worker spawning and app's loading. Any ideas? Is there any hook for that?
> Thank you,
> George Kollias.

Hi George, apply the attached patch and simply
define a uwsgi.post_fork_hook callable:

def hello():
    print "i am the new worker"

uwsgi.post_fork_hook = hello

Roberto De Ioris
-------------- next part --------------
A non-text attachment was scrubbed...
Name: uwsgi_post_fork_hook.patch
Type: application/octet-stream
Size: 705 bytes
Desc: not available
Url : http://lists.unbit.it/pipermail/uwsgi/attachments/20101013/5ee1cd92/attachment.obj 

More information about the uWSGI mailing list