[zeromq-dev] push/pull and multiple workers

Chuck Remes lists at chuckremes.com
Wed Aug 15 15:46:00 CEST 2012

On Aug 15, 2012, at 8:28 AM, andrea crotti wrote:

> Ok thanks is clear now..  But I'm still getting weird errors which I
> can't still quite understand..  For example, suppose I "push" with
> only one process and I "pull" with N clients, is that correct to say
> that the "pusher" should bind the socket, and the client connect??
> So is it normal to get a
> zmq.core.error.ZMQError: Address already in use
> If I try to bind twice to the same port right?

Correct, only one socket may bind to a specific address. This is just like a regular socket.

> And also now I moved the socket creation to another file, which
> contains things like this:
> CONTEXT = None
> def set_context(context):
>    global CONTEXT
>    CONTEXT = context
> def result_recv():
>    return _pull('result')
> def _pull(var):
>    sock = CONTEXT.socket(zmq.PULL)
>    sock.connect(ZMQ_CONF[var])
>    return sock
> And every process has first to create a context and initialise it, and
> the it's able to fetch the correct socket.  Without the set_context
> function nothing seemed to work because probably the same context was
> shared between multiple processes, is that possible?
> Is this a good approach in general?  Because before I did that
> everything seemed to work, but now I'll check again in the repo
> history if there was something different..

You are probably forking when you create your multiple processes. You should create the context in the fork and *not share* it amongst multiple processes. As you can see, it doesn't work.


More information about the zeromq-dev mailing list