當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。