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


Python zmq.RCVTIMEO属性代码示例

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


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

示例1: server_status

# 需要导入模块: import zmq [as 别名]
# 或者: from zmq import RCVTIMEO [as 别名]
def server_status(self):
        """
            Get the current status of the server connected to this client

        :return: a dictionary contains the current status of the server connected to this client
        :rtype: dict[str, str]

        """
        try:
            self.receiver.setsockopt(zmq.RCVTIMEO, self.timeout)
            self._send(b'SHOW_CONFIG')
            return jsonapi.loads(self._recv().content[1])
        except zmq.error.Again as _e:
            t_e = TimeoutError(
                'no response from the server (with "timeout"=%d ms), '
                'is the server on-line? is network broken? are "port" and "port_out" correct?' % self.timeout)
            if _py2:
                raise t_e
            else:
                raise t_e from _e
        finally:
            self.receiver.setsockopt(zmq.RCVTIMEO, -1) 
开发者ID:a414351664,项目名称:Bert-TextClassification,代码行数:24,代码来源:__init__.py

示例2: _timeout

# 需要导入模块: import zmq [as 别名]
# 或者: from zmq import RCVTIMEO [as 别名]
def _timeout(func):
        @wraps(func)
        def arg_wrapper(self, *args, **kwargs):
            if 'blocking' in kwargs and not kwargs['blocking']:
                # override client timeout setting if `func` is called in non-blocking way
                self.receiver.setsockopt(zmq.RCVTIMEO, -1)
            else:
                self.receiver.setsockopt(zmq.RCVTIMEO, self.timeout)
            try:
                return func(self, *args, **kwargs)
            except zmq.error.Again as _e:
                t_e = TimeoutError(
                    'no response from the server (with "timeout"=%d ms), please check the following:'
                    'is the server still online? is the network broken? are "port" and "port_out" correct? '
                    'are you encoding a huge amount of data whereas the timeout is too small for that?' % self.timeout)
                if _py2:
                    raise t_e
                else:
                    _raise(t_e, _e)
            finally:
                self.receiver.setsockopt(zmq.RCVTIMEO, -1)

        return arg_wrapper 
开发者ID:hanxiao,项目名称:bert-as-service,代码行数:25,代码来源:__init__.py

示例3: setUp

# 需要导入模块: import zmq [as 别名]
# 或者: from zmq import RCVTIMEO [as 别名]
def setUp(self):
        """ Create a dummy supvisors, ZMQ context and sockets. """
        from supvisors.supvisorszmq import (InternalEventPublisher,
                                            InternalEventSubscriber)
        # the dummy Supvisors is used for addresses and ports
        self.supvisors = MockedSupvisors()
        # create publisher and subscriber
        self.publisher = InternalEventPublisher(
            self.supvisors.address_mapper.local_address,
            self.supvisors.options.internal_port,
            self.supvisors.logger)
        self.subscriber = InternalEventSubscriber(
            self.supvisors.address_mapper.addresses,
            self.supvisors.options.internal_port)
        # socket configuration is meant to be blocking
        # however, a failure would block the unit test,
        # so a timeout is set for reception
        self.subscriber.socket.setsockopt(zmq.RCVTIMEO, 1000)
        # publisher does not wait for subscriber clients to work,
        # so give some time for connections
        time.sleep(1) 
开发者ID:julien6387,项目名称:supvisors,代码行数:23,代码来源:test_supvisorszmq.py

示例4: __init__

# 需要导入模块: import zmq [as 别名]
# 或者: from zmq import RCVTIMEO [as 别名]
def __init__(self, name, topic: (str, list) = None, *args, **kwargs):
        self.name = name
        self.topic = set(topic if isinstance(topic, list) else
                         [topic]) if topic is not None else set()
        self.ctx = zmq_ctx
        self.sub_socket = self.ctx.socket(zmq.SUB)
        self.sub_socket.setsockopt(zmq.RCVTIMEO, 3000)
        self._thread_pool = ThreadPoolExecutor(max_workers=1)
        self.inproc = set()

        if self.topic:  # 如果topic默认为None,则对所有的topic做处理
            for t in self.topic:
                self.sub_socket.setsockopt(zmq.SUBSCRIBE, pickle.dumps(t))
        else:
            self.sub_socket.subscribe('')

        if kwargs.get('latest', False):  # 可以通过latest(bool)来订阅最新的数据
            self.data_queue = deque(maxlen=1)
            self.latest = True
        else:
            self.data_queue = deque()
            self.latest = False
        self.__active = False 
开发者ID:hadrianl,项目名称:huobi,代码行数:25,代码来源:handler.py

示例5: __init__

# 需要导入模块: import zmq [as 别名]
# 或者: from zmq import RCVTIMEO [as 别名]
def __init__(self, ip_address, rx_incoming_queue):

        self.external_conn_tx = "tcp://{}:{}".format(ip_address, _OLTD_ZEROMQ_OMCI_PORT)
        self.socket_tx = zmq_context.socket(zmq.DEALER)
        self.socket_tx.connect(self.external_conn_tx)

        self.external_conn_rx = "tcp://{}:{}".format(ip_address, _OLTD_ZEROMQ_PUB_OMCI_PORT)
        self.socket_rx = zmq_context.socket(zmq.SUB)
        self.socket_rx.setsockopt(zmq.SUBSCRIBE,'')
        self.socket_rx.setsockopt(zmq.RCVTIMEO,1000)
        self.socket_rx.connect(self.external_conn_rx)
        #self.rx_callback = rx_callback
        self.rx_incoming_queue = rx_incoming_queue
        self.killflag = 0
        
        try:
            thread.start_new_thread(self.omci_receive,())
        except:
            log.exception(e.message) 
开发者ID:opencord,项目名称:voltha,代码行数:21,代码来源:cig_olt_zmq.py

示例6: test_send_message_conn_error

# 需要导入模块: import zmq [as 别名]
# 或者: from zmq import RCVTIMEO [as 别名]
def test_send_message_conn_error(self):
        client = ZeroMQClient("tcp://localhost:5555")
        # Set timeouts
        client.socket.setsockopt(zmq.RCVTIMEO, 5)
        client.socket.setsockopt(zmq.SNDTIMEO, 5)
        client.socket.setsockopt(zmq.LINGER, 5)
        with pytest.raises(zmq.error.ZMQError):
            client.send_message(str(Request("go")), response_expected=True) 
开发者ID:bcb,项目名称:jsonrpcclient,代码行数:10,代码来源:test_zeromq_client.py

示例7: _comm_with_timeout

# 需要导入模块: import zmq [as 别名]
# 或者: from zmq import RCVTIMEO [as 别名]
def _comm_with_timeout(socket, message):
        """
        Exchanges messages via socket with timeout.

        Note:
            socket zmq.RCVTIMEO and zmq.SNDTIMEO should be set to some finite number of milliseconds

        Returns:
            dictionary:
                status: communication result;
                message: received message, if any.
        """
        response=dict(
            status='ok',
            message=None,
        )
        try:
            socket.send_pyobj(message)

        except zmq.ZMQError as e:
            if e.errno == zmq.EAGAIN:
                response['status'] = 'send_failed_due_to_connect_timeout'

            else:
                response['status'] = 'send_failed_for_unknown_reason'
            return response

        start = time.time()
        try:
            response['message'] = socket.recv_pyobj()
            response['time'] =  time.time() - start

        except zmq.ZMQError as e:
            if e.errno == zmq.EAGAIN:
                response['status'] = 'receive_failed_due_to_connect_timeout'

            else:
                response['status'] = 'receive_failed_for_unknown_reason'
            return response

        return response 
开发者ID:Kismuz,项目名称:btgym,代码行数:43,代码来源:server.py

示例8: start_server

# 需要导入模块: import zmq [as 别名]
# 或者: from zmq import RCVTIMEO [as 别名]
def start_server(self):
        """
        Binds the server to the configured host and port and starts listening.
        """
        if self._socket is None:
            context = zmq.Context()
            self._socket = context.socket(zmq.REP)
            self._socket.setsockopt(zmq.RCVTIMEO, 100)
            self._socket.bind('tcp://{0}:{1}'.format(self.host, self.port))

            self.log.info('Listening on %s:%s', self.host, self.port) 
开发者ID:ess-dmsc,项目名称:lewis,代码行数:13,代码来源:control_server.py

示例9: _get_zmq_req_socket

# 需要导入模块: import zmq [as 别名]
# 或者: from zmq import RCVTIMEO [as 别名]
def _get_zmq_req_socket(self):
        context = zmq.Context()
        context.setsockopt(zmq.REQ_CORRELATE, 1)
        context.setsockopt(zmq.REQ_RELAXED, 1)
        context.setsockopt(zmq.SNDTIMEO, self.timeout)
        context.setsockopt(zmq.RCVTIMEO, self.timeout)
        context.setsockopt(zmq.LINGER, 0)
        return context.socket(zmq.REQ) 
开发者ID:ess-dmsc,项目名称:lewis,代码行数:10,代码来源:control_client.py

示例10: test_zmq_socket_uses_timeout

# 需要导入模块: import zmq [as 别名]
# 或者: from zmq import RCVTIMEO [as 别名]
def test_zmq_socket_uses_timeout(self, mock_zmq_context):
        timeout = 100
        ControlClient(host='127.0.0.1', port='10002', timeout=timeout)

        mock_zmq_context.assert_has_calls(
            [call().setsockopt(zmq.SNDTIMEO, timeout), call().setsockopt(zmq.RCVTIMEO, timeout)]) 
开发者ID:ess-dmsc,项目名称:lewis,代码行数:8,代码来源:test_control_client.py

示例11: test_connection

# 需要导入模块: import zmq [as 别名]
# 或者: from zmq import RCVTIMEO [as 别名]
def test_connection(self, mock_context):
        cs = ControlServer(None, connection_string='127.0.0.1:10001')
        cs.start_server()

        mock_context.assert_has_calls([call(), call().socket(zmq.REP),
                                       call().socket().setsockopt(zmq.RCVTIMEO, 100),
                                       call().socket().bind('tcp://127.0.0.1:10001')]) 
开发者ID:ess-dmsc,项目名称:lewis,代码行数:9,代码来源:test_control_server.py

示例12: test_server_can_only_be_started_once

# 需要导入模块: import zmq [as 别名]
# 或者: from zmq import RCVTIMEO [as 别名]
def test_server_can_only_be_started_once(self, mock_context):
        server = ControlServer(None, connection_string='127.0.0.1:10000')
        server.start_server()
        server.start_server()

        mock_context.assert_has_calls([call(), call().socket(zmq.REP),
                                       call().socket().setsockopt(zmq.RCVTIMEO, 100),
                                       call().socket().bind('tcp://127.0.0.1:10000')]) 
开发者ID:ess-dmsc,项目名称:lewis,代码行数:10,代码来源:test_control_server.py

示例13: _SetSocketTimeouts

# 需要导入模块: import zmq [as 别名]
# 或者: from zmq import RCVTIMEO [as 别名]
def _SetSocketTimeouts(self):
    """Sets the timeouts for socket send and receive."""
    # Note that timeout must be an integer value. If timeout is a float
    # it appears that zmq will not enforce the timeout.
    timeout = int(self.timeout_seconds * 1000)
    receive_timeout = min(
        self._ZMQ_SOCKET_RECEIVE_TIMEOUT_MILLISECONDS, timeout)
    send_timeout = min(self._ZMQ_SOCKET_SEND_TIMEOUT_MILLISECONDS, timeout)

    self._zmq_socket.setsockopt(zmq.RCVTIMEO, receive_timeout)
    self._zmq_socket.setsockopt(zmq.SNDTIMEO, send_timeout) 
开发者ID:log2timeline,项目名称:plaso,代码行数:13,代码来源:zeromq_queue.py

示例14: main

# 需要导入模块: import zmq [as 别名]
# 或者: from zmq import RCVTIMEO [as 别名]
def main():
    context     = zmq.Context()
    subscriber  = context.socket(zmq.SUB)
    
    subscriber.setsockopt(zmq.SUBSCRIBE, b"")
    subscriber.setsockopt(zmq.RCVTIMEO, __timeoutEDDN)

    while True:
        try:
            subscriber.connect(__relayEDDN)
            
            while True:
                __message   = subscriber.recv()
                
                if __message == False:
                    subscriber.disconnect(__relayEDDN)
                    break
                
                __message   = zlib.decompress(__message)
                __json      = simplejson.loads(__message)
                
                # call dumps() to ensure double quotes in output
                print(simplejson.dumps(__json))
                sys.stdout.flush()
                
        except zmq.ZMQError as e:
            print ('ZMQSocketException: ' + str(e))
            sys.stdout.flush()
            subscriber.disconnect(__relayEDDN)
            time.sleep(5) 
开发者ID:EDSM-NET,项目名称:EDDN,代码行数:32,代码来源:Client_Simple.py

示例15: _do_connect

# 需要导入模块: import zmq [as 别名]
# 或者: from zmq import RCVTIMEO [as 别名]
def _do_connect(self):

        client_id = str(random.randint(1000000, 100000000))

        socket = self._ctx.socket(zmq.DEALER)
        identity = (client_id) + '$' + str(random.randint(1000000, 1000000000))
        identity = identity.encode('utf-8')
        socket.setsockopt(zmq.IDENTITY, identity)
        socket.setsockopt(zmq.RCVTIMEO, 500)
        socket.setsockopt(zmq.SNDTIMEO, 500)
        socket.setsockopt(zmq.LINGER, 0)
        socket.connect(self._addr)

        return socket 
开发者ID:quantOS-org,项目名称:TradeSim,代码行数:16,代码来源:jrpc_py.py


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