[Python-ideas] Async API: some code to review
yselivanov.ml at gmail.com
Mon Oct 29 20:10:17 CET 2012
On 2012-10-29, at 2:02 PM, Andrew Svetlov <andrew.svetlov at gmail.com> wrote:
> Pollster has to support any object as file descriptor.
> The use case is ZeroMQ sockets: they are implemented at user level and
> socket is just some opaque structure wrapped by Python object.
> ZeroMQ has own poll function to process zmq sockets as well as regular
Well, you can use epoll/select/kqueue or whatever else with ZMQ sockets.
Just get the underlying file descriptor with 'getsockopt', as described
For instance, here is a stripped out zmq support classes I have in my
def __init__(self, *args, **kwargs):
self.fileno = self.getsockopt(FD)
def send(self, data, *, flags=0, copy=True, track=False):
flags |= NOBLOCK
result = _zmq_Socket.send(self, data, flags, copy, track)
except ZMQError as e:
if e.errno != EAGAIN:
self._sending = (Promise(), data, flags, copy, track)
p = Promise()
_socket_class = Socket
And '_schedule_write' accepts any object with 'fileno' property, and
uses an appropriate polling mechanism to poll.
So to use a non-blocking ZMQ sockets, you simply do:
context = Context()
socket = context.socket(zmq.REP)
More information about the Python-ideas