Because by the time the second worker connects, the sender has already sent
both messages to the first one.

The message is not lost. the first worker simply exits after only one
message.


2012/8/15 andrea crotti <[email protected]>

> 2012/8/15 andrea crotti <[email protected]>:
> > 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()
>
>
> I just discovered that adding a sleep between the two send makes it
> actually work, so in the "normal" case one message just gets lost, but
> why??
>
>     task_sender.send('hello')
>     sleep(1)
>     task_sender.send('world')
> _______________________________________________
> zeromq-dev mailing list
> [email protected]
> http://lists.zeromq.org/mailman/listinfo/zeromq-dev
>



-- 


Sincerely yours,

     Apostolis Xekoukoulotakis
_______________________________________________
zeromq-dev mailing list
[email protected]
http://lists.zeromq.org/mailman/listinfo/zeromq-dev

Reply via email to