aio-libs/aiozmq — pull request #38 by aknuds1 (2014-07-24 08:41:47+00:00)
Title: Refactor ZmqEventLoop into mixin

I need to combine aiozmq with [Quamash](https://github.com/harvimt/quamash), the Qt-based asyncio event loop. As such, it's not optimal to use the full ZmqEventLoop, since it "conflicts" with QEventLoop. Instead, I refactored ZmqEventLoop into a mixin that can be combined with other event loops, such as QEventLoop.

I also made it possible to customize socket reading, since this is useful to disable Qt socket notifiers temporarily.

Below is an example of a QEventLoop that integrates ZmqEventLoopMixin:

class EventLoop(aiozmq.ZmqEventLoopMixin, QEventLoop):
def __init__(self, app):
super().__init__(app)

def add_reader(self, sock, *args, **kwargs):
super().add_reader(_get_sock_fd(sock), *args, **kwargs)

def remove_reader(self, sock, *args, **kwargs):
super().remove_reader(_get_sock_fd(sock), *args, **kwargs)

def _read_hook(self, sock):
notifier = self._read_notifiers[_get_sock_fd(sock)]
enabled = notifier.isEnabled()
notifier.setEnabled(False)
try:
data = sock.recv_multipart(zmq.NOBLOCK)
finally:
notifier.setEnabled(enabled)

return data