[zeromq-dev] pyzmq select/_poll implementation problem

Laurens Van Houtven lvh at laurensvh.be
Mon Apr 12 19:58:27 CEST 2010


I'm running into trouble using zmq.select instead of select.select. The end
goal is to get something based on select (specifically, twisted) to be able
to read from ZMQ sockets as well as plain old file descriptors. In a naive
attempt to get that to work, I tried this:


So, I started investigating. Consider the following Python function, in
_zmq.pyx: http://paste.pocoo.org/show/201079/

The sockets list, used as an argument to _poll, is clearly an iterable of
things that can live in {r,w,x}list, so, either:
    - zmq.Socket
    - int (an fd)
    - object implementing fileno returning an int

However, _poll says in its docstring that its sockets argument should be a
list of tuples of (socket, flags). Look at its implementation (
http://paste.pocoo.org/show/201080/, sorry, no syntax highlighting -- I
couldn't find a pastebin that does that for Cython), specifically lines 22
and 23. It appears that _poll isn't lying in its docstring, so it appears
that select isn't feeding it what it wants.

This results in the following problem if I try to use select-using code, but
select.select replaced with zmq.select:


The problem is that in the two aforementioned lines, _zmq.pyx tries to do
sockets[i][0], but sockets[i] is just an integer (specifically, a fd)

What am I missing? The obvious fix of appending (s, flags) instead just
seems a tad *too* obvious. Is zmq.select even supposed to work like this?

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://lists.zeromq.org/pipermail/zeromq-dev/attachments/20100412/cd8239e1/attachment.html>

More information about the zeromq-dev mailing list