[uWSGI] Incompatibility between PyZMQ and uWSGI

Roberto De Ioris roberto at unbit.it
Thu Nov 25 20:42:06 CET 2010


> Thanks. I've modified the sample to:
>
> def application(environ, start_response):
>     import zmq
>     import zmq_context
>     context = zmq_context.context
>     socket_push = context.socket(zmq.PUSH)
>     socket_push.connect('tcp://localhost:9876')
>     socket_push.send_multipart(["Hello", "World"])
>
> and now it works. Probably this is an awful solution because a new context
> is generated for every request (although I'm not sure)
>
> Would you mind to provide a link to the patch? I couldn't find it. Do you
> recommend us to take the latest version of your repository?



The patch is here

http://lists.unbit.it/pipermail/uwsgi/attachments/20101013/5ee1cd92/attachment.obj


I surely do not suggest you to use the development code as this is still
work-in-progress and i do not think there will be a -rc before the middle
of december.

By the way, with the post_fork_hook patch you can rewrite in this way:



import uwsgi
import zmq
import zmq_context

context = None

def set_context():
    context = zmq_context.context


uwsgi.post_fork_hook = set_context

def application(environ, start_response):
    socket_push = context.socket(zmq.PUSH)
    socket_push.connect('tcp://localhost:9876')
    socket_push.send_multipart(["Hello", "World"])


In this way, every time uWSGI calls fork(), the zmq context is re-initialized

-- 
Roberto De Ioris
http://unbit.it


More information about the uWSGI mailing list