当前位置: 首页>>代码示例>>Python>>正文


Python zmq.proxy方法代码示例

本文整理汇总了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') 
开发者ID:achimnol,项目名称:aiotools,代码行数:25,代码来源:zmqserver.py

示例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() 
开发者ID:yl-1993,项目名称:hfsoftmax,代码行数:18,代码来源:paramserver.py

示例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) 
开发者ID:timeflux,项目名称:timeflux,代码行数:18,代码来源:zmq.py

示例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) 
开发者ID:birforce,项目名称:vnpy_crypto,代码行数:5,代码来源:proxydevice.py

示例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 
开发者ID:naripok,项目名称:cryptotrader,代码行数:29,代码来源:datafeed.py

示例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 
开发者ID:cranklin,项目名称:crankycoin,代码行数:17,代码来源:queue.py

示例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) 
开发者ID:timeflux,项目名称:timeflux,代码行数:29,代码来源:zmq.py


注:本文中的zmq.proxy方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。