[zeromq-dev] push/pull and multiple workers

andrea crotti andrea.crotti.0 at gmail.com
Wed Aug 15 15:28:29 CEST 2012


2012/8/15 Chuck Remes <lists at chuckremes.com>:
>
> It hangs for the same reason that the first example hangs. The "connect" action of the two receivers retries asynchronously until they succeed. When either of the receive processes connects, it gets *both* messages. The second receive process hasn't connected yet.
>
> You need to change your timing so that the sender and receiver processes are *all* up and connected before you try sending any data. You'll need to separate out the bind/connect logic, do a short sleep after that (or use a mutex & condition variable to signal completion), and then send your data.
>
> cr
>
>
> _______________________________________________
> zeromq-dev mailing list
> zeromq-dev at lists.zeromq.org
> http://lists.zeromq.org/mailman/listinfo/zeromq-dev

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?

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..



More information about the zeromq-dev mailing list