[zeromq-dev] czmq python binding Zpoller

Johan Philips johan.philips at kuleuven.be
Thu Nov 5 02:50:06 CET 2015


How can I get the actual socket out of it, because Zpoller seems to 
return a c_void_p which I cannot compare to my Zsock object I added to 
the poller.

Minimal example using zyre nodes:
Python 2.7.9 (default, Apr  2 2015, 15:33:21)
[GCC 4.9.2] on linux2
Type "help", "copyright", "credits" or "license" for more information.
 >>> from zyre import Zyre
 >>> from czmq import Zsock, Zpoller
 >>> n1 = Zyre("n1")
 >>> n2 = Zyre("n2")
 >>> n1.start()
0
 >>> n2.start()
0
 >>> poller = Zpoller(n1.socket(),n2.socket(), None)
 >>> sock = poller.wait(100)
 >>> print sock
c_void_p(27301232)
 >>> print n1.socket(), n2.socket()
<czmq.Zsock object at 0x7fbd0968cfd0> <czmq.Zsock object at 0x7fbd0968cfd0>
 >>>

Do I need to add cast or POINTER or is there a more convenient way?
Zsock(result, True) does not work since it will create a new object.

Thanks!

Johan


On 2015-11-05 08:04, Johan Philips wrote:
>
>
> On 2015-11-05 07:58, Arnaud Loonstra wrote:
>> Indeed, it was fixed last night. Did you test that?
>
> got the new code now. Should work, thanks!
>>
>> Rg,
>>
>> Arnaud
>>
>> On November 4, 2015 9:53:42 PM GMT+01:00, Johan Philips
>> <johan.philips at kuleuven.be> wrote:
>>
>>
>>
>>      On 2015-11-04 20:38, Arnaud Loonstra wrote:
>>
>>          On 2015-11-03 22:55, Johan Philips wrote:
>>
>>              On 2015-11-03 19:31, Arnaud Loonstra wrote:
>>
>>                  I think you are right. Have you tried removing index().
>>
>>
>>              Yes and that silences the error but how can I add 2 sockets
>>              to the
>>              poller? Is the only way by using the 'add' method?
>>
>>              In zpoller (the C version) you could stack them in the
>>              constructor.
>>              i.e.
>>              zpoller_new(socket1, socket2, NULL)
>>
>>              In python this results in:
>>
>>              Traceback (most recent call last):
>>              File "zyre_test.py <http://test.py>", line 12, in <module>
>>              poller = Zpoller(n1,n2,None)
>>              File "/home/jphilips/workspace/czmq/bindings/python/czmq.py
>>              <http://czmq.py>", line
>>              1781, in __init__
>>              assert(len(args) == 2)
>>              AssertionError
>>              Exception AttributeError: "'Zpoller' object has no attribute
>>              'allow_destruct'" in <bound method Zpoller.__del__ of
>>              <czmq.Zpoller
>>              object at 0x7f53f7a6d590>> ignored
>>
>>
>>          Ah I understand it now. You get an assertion error in the
>>          constructor
>>          before the
>>          allow_destruct bool can be set. So in the destructor you get another
>>          error because the
>>          allow_destruct isn't set. So the first error is a bug, the
>>          second can
>>          be blamed on python
>>          allowing dynamic types. We could prevent it by assigning
>>          allow_destruct
>>          earlier but it
>>          shouldn't be a problem. I think it is fixed here
>>          https://github.com/zeromq/zproject/pull/271
>>
>>
>>      I've pulled that code before but the assertion of 2 arguments is, in my
>>      opinion, a "bug" because we want the constructor to be variadic, right?
>>
>>
>>          The binding for czmq is updated as well. Just pull from the latest
>>          master.
>>
>>          Rg,
>>
>>          Arnaud
>>          ------------------------------------------------------------------------
>>
>>          zeromq-dev mailing list
>>          zeromq-dev at lists.zeromq.org
>>          http://lists.zeromq.org/mailman/listinfo/zeromq-dev
>>
>>
>>      ------------------------------------------------------------------------
>>
>>      zeromq-dev mailing list
>>      zeromq-dev at lists.zeromq.org
>>      http://lists.zeromq.org/mailman/listinfo/zeromq-dev
>>
>>
>> Send from my feature bloated phone.
>>
>>
>> _______________________________________________
>> zeromq-dev mailing list
>> zeromq-dev at lists.zeromq.org
>> http://lists.zeromq.org/mailman/listinfo/zeromq-dev
>>
> _______________________________________________
> zeromq-dev mailing list
> zeromq-dev at lists.zeromq.org
> http://lists.zeromq.org/mailman/listinfo/zeromq-dev
>



More information about the zeromq-dev mailing list