[zeromq-dev] python3 2 threads and PAIR sockets, when to close?
Arnaud Kapp
kapp.arno at gmail.com
Fri Sep 18 18:44:46 CEST 2015
> For a PAIR socket, between 2 threads, does the binder need to bind before the connector connects?
Depends on libzmq's version. With current trunk it works. I believe it
also works in 4.1. Not sure though.
> Can the sender close the socket as soon as they have send_pyobj, and the other thread would receive anyways?
I don't know if send_pyobj() is special (I don't know much about GC /
refcounting in Python), but I believe
it should be alright.
On Fri, Sep 18, 2015 at 4:13 PM, MM <finjulhich at gmail.com> wrote:
>
>
> 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,
>
>
> _______________________________________________
> zeromq-dev mailing list
> zeromq-dev at lists.zeromq.org
> http://lists.zeromq.org/mailman/listinfo/zeromq-dev
>
--
Kapp Arnaud - Xaqq
More information about the zeromq-dev
mailing list