[zeromq-dev] push/pull and multiple workers

andrea crotti andrea.crotti.0 at gmail.com
Wed Aug 15 12:40:53 CEST 2012


I'm having a few problems with PUSH/PULL and multiple processes, so I
tried to make a simple example to understand what's going on, but
still is not clear..

In the following example I would expect to receive two tasks from the
two different processes and then quit, instead it receives the first
one and then hangs..  Why is that? (Also using ipc instead of tcp
produces the same behaviour).

Are there issues with multiprocessing for example that I should be
aware of?

import zmq
from time import sleep
from multiprocessing import Process

# TODO: this only works on Linux
PORT = 'tcp://127.0.0.1:4444'


def start_send():
    ctx = zmq.Context()
    task_sender = ctx.socket(zmq.PUSH)
    task_sender.bind(PORT)
    task_sender.send('hello')
    task_sender.send('world')


def start_receive():
    ctx = zmq.Context()
    task_recv = ctx.socket(zmq.PULL)
    task_recv.connect(PORT)
    msg = task_recv.recv()
    print(msg)


if __name__ == '__main__':
    p1 = Process(target=start_send)
    p2 = Process(target=start_receive)
    p3 = Process(target=start_receive)
    p1.start()
    p2.start()
    p3.start()



More information about the zeromq-dev mailing list