
A new hub: This closely mirrors the poll hub with some of the internal logic changed to reflect zmq's flags. A green module for zmq: This subclasses Context and Socket to ensure calls are non blocking. A (very sparse) beginings of a test module. An example: A melding of the pyzmq chat example and the eventlet telnet chat example. TODO zmq_poll chokes if the sockets passed to it come from different contexts. As context is the entry point to everything else then it would make sense to include a check in here that each thread has only one context instance. By context being the entry point I mean: ctx = zmq.Context() socket = ctx.socket(zmq.<type-of-socket>) This call to socket is repeated for each socket you want and ctx must be the same one for each thread. Tests. I'd like to get to the point f having all zmq socket pairs tested - and perhaps a nice benchmark suite too.
67 lines
1.9 KiB
Python
67 lines
1.9 KiB
Python
__zmq__ = __import__('zmq')
|
|
from eventlet.hubs import trampoline
|
|
__patched__ = ['Context', 'Socket']
|
|
globals().update(dict([(var, getattr(__zmq__, var))
|
|
for var in __zmq__.__all__
|
|
if not (var.startswith('__')
|
|
or
|
|
var in __patched__)
|
|
]))
|
|
|
|
class Context(__zmq__.Context):
|
|
|
|
def socket(self, socket_type):
|
|
return Socket(self, socket_type)
|
|
|
|
class Socket(__zmq__.Socket):
|
|
|
|
|
|
def _send_message(self, data, flags=0, copy=True):
|
|
# flags |= __zmq__.NOBLOCK
|
|
print 'send'
|
|
while True:
|
|
try:
|
|
return super(Socket, self)._send_message(data, flags)
|
|
except __zmq__.ZMQError, e:
|
|
if e.errno != EAGAIN:
|
|
raise
|
|
trampoline(self, read=True)
|
|
|
|
def _send_copy(self, data, flags=0, copy=True):
|
|
# flags |= __zmq__.NOBLOCK
|
|
while True:
|
|
try:
|
|
return super(Socket, self)._send_copy(data, flags)
|
|
except __zmq__.ZMQError, e:
|
|
if e.errno != EAGAIN:
|
|
raise
|
|
trampoline(self, write=True)
|
|
|
|
def _recv_message(self, flags=0):
|
|
|
|
flags |= __zmq__.NOBLOCK
|
|
while True:
|
|
try:
|
|
m = super(Socket, self)._recv_message(flags)
|
|
if m:
|
|
return m
|
|
except __zmq__.ZMQError, e:
|
|
if e.errno != EAGAIN:
|
|
raise
|
|
trampoline(self, read=True)
|
|
|
|
def _recv_copy(self, flags=0):
|
|
flags |= __zmq__.NOBLOCK
|
|
while True:
|
|
try:
|
|
m = super(Socket, self)._recv_copy(flags)
|
|
if m:
|
|
return m
|
|
except __zmq__.ZMQError, e:
|
|
if e.errno != EAGAIN:
|
|
raise
|
|
trampoline(self, read=True)
|
|
|
|
|
|
|
|
|