Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
import asyncio
import aiozmq
import zmq
class ZmqDealerProtocol(aiozmq.ZmqProtocol):
transport = None
def __init__(self, queue, on_close):
self.queue = queue
self.on_close = on_close
def connection_made(self, transport):
self.transport = transport
def msg_received(self, msg):
self.queue.put_nowait(msg)
def connection_lost(self, exc):
self.on_close.set_result(exc)
def __init__(self, queue, on_close):
self.queue = queue
self.on_close = on_close
def connection_made(self, transport):
self.transport = transport
def msg_received(self, msg):
self.queue.put_nowait(msg)
def connection_lost(self, exc):
self.on_close.set_result(exc)
class ZmqRouterProtocol(aiozmq.ZmqProtocol):
transport = None
def __init__(self, on_close):
self.on_close = on_close
def connection_made(self, transport):
self.transport = transport
def msg_received(self, msg):
self.transport.write(msg)
def connection_lost(self, exc):
self.on_close.set_result(exc)
transport = None
def __init__(self, on_close):
self.on_close = on_close
def connection_made(self, transport):
self.transport = transport
def msg_received(self, msg):
self.transport.write(msg)
def connection_lost(self, exc):
self.on_close.set_result(exc)
class ZmqDealerProtocol(aiozmq.ZmqProtocol):
transport = None
def __init__(self, count, on_close):
self.count = count
self.on_close = on_close
def connection_made(self, transport):
self.transport = transport
def msg_received(self, msg):
self.count -= 1
if self.count:
self.transport.write(msg)
else:
self.transport.close()
import asyncio
import aiozmq
import zmq
ZMQ_EVENTS = {
getattr(zmq, name): name.replace('EVENT_', '').lower().replace('_', ' ')
for name in [i for i in dir(zmq) if i.startswith('EVENT_')]}
def event_description(event):
''' Return a human readable description of the event '''
return ZMQ_EVENTS.get(event, 'unknown')
class Protocol(aiozmq.ZmqProtocol):
def __init__(self):
self.wait_ready = asyncio.Future()
self.wait_done = asyncio.Future()
self.wait_closed = asyncio.Future()
self.count = 0
def connection_made(self, transport):
self.transport = transport
self.wait_ready.set_result(True)
def connection_lost(self, exc):
self.wait_closed.set_result(exc)
def msg_received(self, data):
# This protocol is used by both the Router and Dealer sockets in
th = threading.Thread(target=router_thread)
th.start()
gc.collect()
t1 = time.monotonic()
for i in range(count):
dealer.send_multipart(msg)
dealer.recv_multipart()
t2 = time.monotonic()
gc.collect()
th.join()
dealer.close()
ctx.destroy()
return t2 - t1
class ZmqRouterProtocol(aiozmq.ZmqProtocol):
transport = None
def __init__(self, on_close):
self.on_close = on_close
def connection_made(self, transport):
self.transport = transport
def msg_received(self, msg):
self.transport.write(msg)
def connection_lost(self, exc):
self.on_close.set_result(exc)