[zeromq-dev] python3 2 threads and PAIR sockets, when to close?

MM finjulhich at gmail.com
Fri Sep 18 16:13:52 CEST 2015


On 3 September 2015 at 15:58, MM <finjulhich at gmail.com> wrote:

> hello
>
> I have:
>
> def thread1():
>   s = context.socket(zmq.PAIR)
>   s.bind('inproc://name')
>   s.send_pyobj( dictionary )
>   ### That's all I need to do , can I close s here?
>   while True:
>        # stay alive forever
>
> def thread2():
>    s = context.socket(zmq.PAIR)
>    s.connect('inproc://name')
>    dx = s.recv_pyobj()
>    while True:
>        # stay alive forever
>
> def main():
>   Thread(....thread1..).start()
>    time.sleep(5) #5secs
>   Thread(....thread2..).start()
>   #wait for signals
>
>
> thread1 is the parent one, proceeds independently.
> thread2 can only proceed once it got the dictionary from thread1
>
> 1. do I need the sleep(5) in the main thread to ensure thread1 bind
> happens before thread2 connect?
> 2. can I close s in thread1 as soon as I send the dictionary?
>
> Thanks,
>

Apologies if the answers to these questions are in the manual, I couldn't
see them.

For a PAIR socket, between 2 threads, does the binder need to bind before
the connector connects?
Can the sender close the socket as soon as they have send_pyobj, and the
other thread would receive anyways?

Regards,
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://lists.zeromq.org/pipermail/zeromq-dev/attachments/20150918/eb9c6e5b/attachment.htm>


More information about the zeromq-dev mailing list