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


Python zmq.ROUTER属性代码示例

本文整理汇总了Python中zmq.ROUTER属性的典型用法代码示例。如果您正苦于以下问题:Python zmq.ROUTER属性的具体用法?Python zmq.ROUTER怎么用?Python zmq.ROUTER使用的例子?那么恭喜您, 这里精选的属性代码示例或许可以为您提供帮助。您也可以进一步了解该属性所在zmq的用法示例。


在下文中一共展示了zmq.ROUTER属性的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: _do_heartbeat

# 需要导入模块: import zmq [as 别名]
# 或者: from zmq import ROUTER [as 别名]
def _do_heartbeat(self):
        while True:
            try:
                if self._socket.getsockopt(zmq.TYPE) == zmq.ROUTER:
                    yield from self._do_router_heartbeat()
                elif self._socket.getsockopt(zmq.TYPE) == zmq.DEALER:
                    yield from self._do_dealer_heartbeat()
                yield from asyncio.sleep(self._heartbeat_interval,
                                         loop=self._event_loop)
            except CancelledError:  # pylint: disable=try-except-raise
                # The concurrent.futures.CancelledError is caught by asyncio
                # when the Task associated with the coroutine is cancelled.
                # The raise is required to stop this component.
                raise
            except Exception as e:  # pylint: disable=broad-except
                LOGGER.exception(
                    "An error occurred while sending heartbeat: %s", e) 
开发者ID:hyperledger,项目名称:sawtooth-core,代码行数:19,代码来源:interconnect.py

示例2: test_hwm

# 需要导入模块: import zmq [as 别名]
# 或者: from zmq import ROUTER [as 别名]
def test_hwm(self):
        zmq3 = zmq.zmq_version_info()[0] >= 3
        for stype in (zmq.PUB, zmq.ROUTER, zmq.SUB, zmq.REQ, zmq.DEALER):
            s = self.context.socket(stype)
            s.hwm = 100
            self.assertEqual(s.hwm, 100)
            if zmq3:
                try:
                    self.assertEqual(s.sndhwm, 100)
                except AttributeError:
                    pass
                try:
                    self.assertEqual(s.rcvhwm, 100)
                except AttributeError:
                    pass
            s.close() 
开发者ID:birforce,项目名称:vnpy_crypto,代码行数:18,代码来源:test_socket.py

示例3: test_custom_serialize_error

# 需要导入模块: import zmq [as 别名]
# 或者: from zmq import ROUTER [as 别名]
def test_custom_serialize_error(self):
        @asyncio.coroutine
        def test():
            a, b = self.create_bound_pair(zmq.DEALER, zmq.ROUTER)

            msg = {
                'content': {
                    'a': 5,
                    'b': 'bee',
                }
            }
            with pytest.raises(TypeError):
                yield from a.send_serialized(json, json.dumps)

            yield from a.send(b'not json')
            with pytest.raises(TypeError):
                recvd = yield from b.recv_serialized(json.loads)
        self.loop.run_until_complete(test()) 
开发者ID:birforce,项目名称:vnpy_crypto,代码行数:20,代码来源:_test_asyncio.py

示例4: test_custom_serialize_error

# 需要导入模块: import zmq [as 别名]
# 或者: from zmq import ROUTER [as 别名]
def test_custom_serialize_error(self):
        @gen.coroutine
        def test():
            a, b = self.create_bound_pair(zmq.DEALER, zmq.ROUTER)

            msg = {
                'content': {
                    'a': 5,
                    'b': 'bee',
                }
            }
            with pytest.raises(TypeError):
                yield a.send_serialized(json, json.dumps)

            yield a.send(b'not json')
            with pytest.raises(TypeError):
                recvd = yield b.recv_serialized(json.loads)
        self.loop.run_sync(test) 
开发者ID:birforce,项目名称:vnpy_crypto,代码行数:20,代码来源:test_future.py

示例5: handle_result

# 需要导入模块: import zmq [as 别名]
# 或者: from zmq import ROUTER [as 别名]
def handle_result(self, idents, parent, raw_msg, success=True):
        """handle a real task result, either success or failure"""
        # first, relay result to client
        engine = idents[0]
        client = idents[1]
        # swap_ids for ROUTER-ROUTER mirror
        raw_msg[:2] = [client,engine]
        # print (map(str, raw_msg[:4]))
        self.client_stream.send_multipart(raw_msg, copy=False)
        # now, update our data structures
        msg_id = parent['msg_id']
        self.pending[engine].pop(msg_id)
        if success:
            self.completed[engine].add(msg_id)
            self.all_completed.add(msg_id)
        else:
            self.failed[engine].add(msg_id)
            self.all_failed.add(msg_id)
        self.all_done.add(msg_id)
        self.destinations[msg_id] = engine

        self.update_graph(msg_id, success) 
开发者ID:ktraunmueller,项目名称:Computable,代码行数:24,代码来源:scheduler.py

示例6: init_sockets

# 需要导入模块: import zmq [as 别名]
# 或者: from zmq import ROUTER [as 别名]
def init_sockets(self):
        # Create a context, a session, and the kernel sockets.
        self.log.info("Starting the kernel at pid: %i", os.getpid())
        context = zmq.Context.instance()
        # Uncomment this to try closing the context.
        # atexit.register(context.term)

        self.shell_socket = context.socket(zmq.ROUTER)
        self.shell_port = self._bind_socket(self.shell_socket, self.shell_port)
        self.log.debug("shell ROUTER Channel on port: %i" % self.shell_port)

        self.iopub_socket = context.socket(zmq.PUB)
        self.iopub_port = self._bind_socket(self.iopub_socket, self.iopub_port)
        self.log.debug("iopub PUB Channel on port: %i" % self.iopub_port)

        self.stdin_socket = context.socket(zmq.ROUTER)
        self.stdin_port = self._bind_socket(self.stdin_socket, self.stdin_port)
        self.log.debug("stdin ROUTER Channel on port: %i" % self.stdin_port)

        self.control_socket = context.socket(zmq.ROUTER)
        self.control_port = self._bind_socket(self.control_socket, self.control_port)
        self.log.debug("control ROUTER Channel on port: %i" % self.control_port) 
开发者ID:ktraunmueller,项目名称:Computable,代码行数:24,代码来源:kernelapp.py

示例7: __init__

# 需要导入模块: import zmq [as 别名]
# 或者: from zmq import ROUTER [as 别名]
def __init__(self, port=None, min_port=5000, max_port=9999, pipeline=100, log_file=None):
        """Create a new ZMQDealer object.
        """
        context = zmq.Context.instance()
        # noinspection PyUnresolvedReferences
        self.socket = context.socket(zmq.ROUTER)
        self.socket.hwm = pipeline
        if port is not None:
            self.socket.bind('tcp://*:%d' % port)
            self.port = port
        else:
            self.port = self.socket.bind_to_random_port('tcp://*', min_port=min_port, max_port=max_port)
        self.addr = None
        self._log_file = log_file

        if self._log_file is not None:
            self._log_file = os.path.abspath(self._log_file)
            # If log file directory does not exists, create it
            log_dir = os.path.dirname(self._log_file)
            if not os.path.exists(log_dir):
                os.makedirs(log_dir)
            # clears any existing log
            if os.path.exists(self._log_file):
                os.remove(self._log_file) 
开发者ID:ucb-art,项目名称:BAG_framework,代码行数:26,代码来源:zmqwrapper.py

示例8: createZMQSocket

# 需要导入模块: import zmq [as 别名]
# 或者: from zmq import ROUTER [as 别名]
def createZMQSocket(self, sock_type):
        """Create a socket of the given sock_type and deactivate message dropping"""
        sock = self.ZMQcontext.socket(sock_type)
        sock.setsockopt(zmq.LINGER, LINGER_TIME)
        sock.setsockopt(zmq.IPV4ONLY, 0)

        # Remove message dropping
        sock.setsockopt(zmq.SNDHWM, 0)
        sock.setsockopt(zmq.RCVHWM, 0)
        try:
            sock.setsockopt(zmq.IMMEDIATE, 1)
        except:
            # This parameter was recently added by new libzmq versions
            pass

        # Don't accept unroutable messages
        if sock_type == zmq.ROUTER:
            sock.setsockopt(zmq.ROUTER_MANDATORY, 1)
        return sock 
开发者ID:soravux,项目名称:scoop,代码行数:21,代码来源:scoopzmq.py

示例9: __init__

# 需要导入模块: import zmq [as 别名]
# 或者: from zmq import ROUTER [as 别名]
def __init__(self, name, send_qsize=0, mode='tcp'):
        self._name = name
        self._conn_info = None

        self._context_lock = threading.Lock()
        self._context = zmq.Context()
        self._tosock = self._context.socket(zmq.ROUTER)
        self._frsock = self._context.socket(zmq.PULL)
        self._tosock.set_hwm(10)
        self._frsock.set_hwm(10)
        self._dispatcher = CallbackRegistry()

        self._send_queue = queue.Queue(maxsize=send_qsize)
        self._rcv_thread = None
        self._snd_thread = None
        self._mode = mode
        assert mode in ('ipc', 'tcp') 
开发者ID:vacancy,项目名称:Jacinle,代码行数:19,代码来源:cs.py

示例10: run

# 需要导入模块: import zmq [as 别名]
# 或者: from zmq import ROUTER [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

示例11: dealer_interchange

# 需要导入模块: import zmq [as 别名]
# 或者: from zmq import ROUTER [as 别名]
def dealer_interchange(manager_ip="localhost", manager_port=5559,
                       worker_port=5560):
    context = zmq.Context()
    incoming = context.socket(zmq.ROUTER)
    outgoing = context.socket(zmq.DEALER)

    incoming.connect("tcp://{}:{}".format(manager_ip, manager_port))
    outgoing.bind("tcp://*:{}".format(worker_port))

    poller = zmq.Poller()
    poller.register(incoming, zmq.POLLIN)
    poller.register(outgoing, zmq.POLLIN)

    while True:
        socks = dict(poller.poll(1))

        if socks.get(incoming) == zmq.POLLIN:
            message = incoming.recv_multipart()
            logger.debug("[interchange] New task {}".format(message))
            outgoing.send_multipart(message)

        if socks.get(outgoing) == zmq.POLLIN:
            message = outgoing.recv_multipart()
            logger.debug("[interchange] New result {}".format(message))
            incoming.send_multipart(message) 
开发者ID:Parsl,项目名称:parsl,代码行数:27,代码来源:interchange.py

示例12: _receive_message

# 需要导入模块: import zmq [as 别名]
# 或者: from zmq import ROUTER [as 别名]
def _receive_message(self):
        """
        Internal coroutine for receiving messages
        """
        while True:
            try:
                if self._socket.getsockopt(zmq.TYPE) == zmq.ROUTER:
                    zmq_identity, msg_bytes = \
                        yield from self._socket.recv_multipart()
                    if msg_bytes == b'':
                        # send ACK for connection probes
                        LOGGER.debug("ROUTER PROBE FROM %s", zmq_identity)
                        self._socket.send_multipart(
                            [bytes(zmq_identity), msg_bytes])
                    else:
                        self._received_from_identity(zmq_identity)
                        self._dispatcher_queue.put_nowait(
                            (zmq_identity, msg_bytes))
                else:
                    msg_bytes = yield from self._socket.recv()
                    self._last_message_time = time.time()
                    self._dispatcher_queue.put_nowait((None, msg_bytes))
                self._get_queue_size_gauge(self.connection).set_value(
                    self._dispatcher_queue.qsize())

            except CancelledError:  # pylint: disable=try-except-raise
                # The concurrent.futures.CancelledError is caught by asyncio
                # when the Task associated with the coroutine is cancelled.
                # The raise is required to stop this component.
                raise
            except Exception as e:  # pylint: disable=broad-except
                LOGGER.exception("Received a message on address %s that "
                                 "caused an error: %s", self._address, e) 
开发者ID:hyperledger,项目名称:sawtooth-core,代码行数:35,代码来源:interconnect.py

示例13: start

# 需要导入模块: import zmq [as 别名]
# 或者: from zmq import ROUTER [as 别名]
def start(self):
        complete_or_error_queue = queue.Queue()
        self._thread = InstrumentedThread(
            target=self._send_receive_thread.setup,
            args=(zmq.ROUTER, complete_or_error_queue))
        self._thread.name = self.__class__.__name__ + self._thread.name
        self._thread.start()
        # Blocking in startup until the background thread has made it to
        # running the event loop or error.
        err = complete_or_error_queue.get(block=True)
        if err != _STARTUP_COMPLETE_SENTINEL:
            raise err 
开发者ID:hyperledger,项目名称:sawtooth-core,代码行数:14,代码来源:interconnect.py

示例14: run

# 需要导入模块: import zmq [as 别名]
# 或者: from zmq import ROUTER [as 别名]
def run(websocket_port, zmq_address, num_tokens, input_queue_maxsize,
        timeout=FIVE_SECONDS, message_max_size=None):
    context = zmq.asyncio.Context()
    zmq_socket = context.socket(zmq.ROUTER)
    zmq_socket.bind(zmq_address)
    logger.info('Waiting for engines to connect')

    server = _Server(num_tokens, zmq_socket, timeout, input_queue_maxsize)
    server.launch(websocket_port, message_max_size) 
开发者ID:cmusatyalab,项目名称:gabriel,代码行数:11,代码来源:server_runner.py

示例15: test_custom_serialize

# 需要导入模块: import zmq [as 别名]
# 或者: from zmq import ROUTER [as 别名]
def test_custom_serialize(self):
        a, b = self.create_bound_pair(zmq.DEALER, zmq.ROUTER)
        def serialize(msg):
            frames = []
            frames.extend(msg.get('identities', []))
            content = json.dumps(msg['content']).encode('utf8')
            frames.append(content)
            return frames
        
        def deserialize(frames):
            identities = frames[:-1]
            content = json.loads(frames[-1].decode('utf8'))
            return {
                'identities': identities,
                'content': content,
            }
        
        msg = {
            'content': {
                'a': 5,
                'b': 'bee',
            }
        }
        a.send_serialized(msg, serialize)
        recvd = b.recv_serialized(deserialize)
        assert recvd['content'] == msg['content']
        assert recvd['identities']
        # bounce back, tests identities
        b.send_serialized(recvd, serialize)
        r2 = a.recv_serialized(deserialize)
        assert r2['content'] == msg['content']
        assert not r2['identities'] 
开发者ID:birforce,项目名称:vnpy_crypto,代码行数:34,代码来源:test_socket.py


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