[zeromq-dev] Design question: python interface for zmq_poll

Martin Sustrik sustrik at 250bpm.com
Tue Feb 16 22:08:06 CET 2010


Brian,

> My Python bindings have support for zmq_poll now:
> 
> http://github.com/ellisonbg/pyzmq/blob/master/zmq/_zmq.pyx#L436
> 
> This handles both 0MQ sockets as well as any Python object that has a fileno()
> function (sockets, files, etc.)

Nice! AFAIK this is the first binding (aside of C and C++) that's able 
to combine polling for BSD and 0MQ sockets.

> Currently, the interface is similar to the underlying zmq_poll
> function.  I am thinking about
> providing a slightly different interface that would be more familiar
> to Python devs and wanted
> to get feedback.
> 
> The most familiar interfaces for non-blocking IO are select and poll.
> Python comes with
> an implementation of both of these things (OS dependent of course).
> This is described here:
> 
> http://docs.python.org/library/select.html
> 
> I am thinking of wrapping my currently version of poll into two higher
> level functions that
> mimic Python's builtin select and poll interfaces:
> 
> * I would write a zmq.select function that has the same interface as
> the built-in select.select but
> calls zmq_poll underneath.
> 
> * I would create a simple Python object (Poller) that has the same
> interface as the built-in select.poll.
> 
> This would give Python devs the same exact interfaces they have with
> regular sockets.  What do
> people think about this?  My only hesitancy is that this is a
> departure from the 0MQ zmq_poll
> interface, so 0MQ devs coming from C/Java, etc will find the interface
> quite different.
> I could also provide all 3 interfaces and give the dev a choice.

I am not a Python developer so my vote doesn't count, however, I would 
refrain from providing multiple APIs for the same functionality. That's 
just asking for maintenance trouble. Also, I wouldn't be afraid of 
departing from undelying C API if there's a widely accepted API for this 
kind of thing in Python. The goal is to make life easier for Python 
developers rather than copying C API verbatim.

Martin



More information about the zeromq-dev mailing list