本文整理汇总了Python中zmq.proxy方法的典型用法代码示例。如果您正苦于以下问题:Python zmq.proxy方法的具体用法?Python zmq.proxy怎么用?Python zmq.proxy使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类zmq
的用法示例。
在下文中一共展示了zmq.proxy方法的7个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: router_main
# 需要导入模块: import zmq [as 别名]
# 或者: from zmq import proxy [as 别名]
def router_main(_, pidx, args):
log = get_logger('examples.zmqserver.extra', pidx)
zctx = zmq.Context()
zctx.linger = 0
in_sock = zctx.socket(zmq.PULL)
in_sock.bind('tcp://*:5033')
out_sock = zctx.socket(zmq.PUSH)
out_sock.bind('ipc://example-events')
try:
log.info('router proxy started')
zmq.proxy(in_sock, out_sock)
except KeyboardInterrupt:
pass
except Exception:
log.exception('unexpected error')
finally:
for _ in range(num_workers):
out_sock.send(b'') # sentinel
log.info('router proxy terminated')
in_sock.close()
out_sock.close()
zctx.term()
os.unlink('example-events')
示例2: run
# 需要导入模块: import zmq [as 别名]
# 或者: from zmq import proxy [as 别名]
def run(self):
context = zmq.Context()
frontend = context.socket(zmq.ROUTER)
frontend.bind('tcp://*:5570')
backend = context.socket(zmq.DEALER)
backend.bind('inproc://backend')
worker = ParameterWorker(context)
worker.start()
try:
zmq.proxy(frontend, backend)
except zmq.ContextTerminated:
frontend.close()
backend.close()
示例3: update
# 需要导入模块: import zmq [as 别名]
# 或者: from zmq import proxy [as 别名]
def update(self):
"""Monitor proxy"""
if self._timeout == 0:
pass
now = time.time()
count = 0
try:
while True:
self._monitor.recv_multipart(zmq.NOBLOCK, copy=False)
self._last_event = now
count += 1
except zmq.ZMQError:
if count > 0:
self.logger.debug("Received %d messages", count)
if (now - self._last_event) > self._timeout:
raise WorkerInterrupt("No data after %d seconds" % self._timeout)
示例4: run_device
# 需要导入模块: import zmq [as 别名]
# 或者: from zmq import proxy [as 别名]
def run_device(self):
ins,outs,mons = self._setup_sockets()
zmq.proxy(ins, outs, mons)
示例5: run
# 需要导入模块: import zmq [as 别名]
# 或者: from zmq import proxy [as 别名]
def run(self):
try:
Logger.info(FeedDaemon, "Starting Feed Daemon...")
# Socket to talk to clients
clients = self.context.socket(zmq.ROUTER)
clients.bind(self.addr)
# Socket to talk to workers
workers = self.context.socket(zmq.DEALER)
workers.bind("inproc://workers.inproc")
# Launch pool of worker threads
for i in range(self.n_workers):
thread = threading.Thread(target=self.worker, args=())
thread.start()
Logger.info(FeedDaemon.run, "Feed Daemon running. Serving on %s" % self.addr)
zmq.proxy(clients, workers)
except KeyboardInterrupt:
clients.close()
workers.close()
self.context.term()
# Client
示例6: start_queue
# 需要导入模块: import zmq [as 别名]
# 或者: from zmq import proxy [as 别名]
def start_queue(cls):
try:
context = zmq.Context(1)
# Socket facing producers
frontend = context.socket(zmq.PULL)
frontend.bind(cls.QUEUE_BIND_IN)
# Socket facing consumers
backend = context.socket(zmq.PUSH)
backend.bind(cls.QUEUE_BIND_OUT)
zmq.proxy(frontend, backend)
except Exception as e:
logger.error("could not start queue: %s", e)
raise
示例7: __init__
# 需要导入模块: import zmq [as 别名]
# 或者: from zmq import proxy [as 别名]
def __init__(
self,
address_in="tcp://127.0.0.1:5559",
address_out="tcp://127.0.0.1:5560",
timeout=5,
):
self._timeout = timeout
try:
# Capture
address_monitor = "inproc://monitor"
context = zmq.Context.instance()
self._monitor = context.socket(zmq.PULL)
self._monitor.bind(address_monitor)
# Proxy
proxy = ThreadProxy(zmq.XSUB, zmq.XPUB, zmq.PUSH)
proxy.bind_in(address_in)
proxy.bind_out(address_out)
proxy.connect_mon(address_monitor)
# proxy.setsockopt_mon(zmq.CONFLATE, True) # Do not clutter the network
proxy.start()
except zmq.ZMQError as error:
self.logger.error(error)