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


Python zmq.SNDTIMEO属性代码示例

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


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

示例1: test_send_message_conn_error

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

示例2: _comm_with_timeout

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

示例3: _get_zmq_req_socket

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

示例4: test_zmq_socket_uses_timeout

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

示例5: _SetSocketTimeouts

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

示例6: setUp

# 需要导入模块: import zmq [as 别名]
# 或者: from zmq import SNDTIMEO [as 别名]
def setUp(self):
        """ Create a dummy supvisors, ZMQ context and sockets. """
        from supvisors.supvisorszmq import RequestPusher, RequestPuller
        # the dummy Supvisors is used for addresses and ports
        self.supvisors = MockedSupvisors()
        # create pusher and puller
        self.pusher = RequestPusher(self.supvisors.logger)
        self.puller = RequestPuller()
        # socket configuration is meant to be blocking
        # however, a failure would block the unit test,
        # so a timeout is set for emission and reception
        self.puller.socket.setsockopt(zmq.SNDTIMEO, 1000)
        self.puller.socket.setsockopt(zmq.RCVTIMEO, 1000) 
开发者ID:julien6387,项目名称:supvisors,代码行数:15,代码来源:test_supvisorszmq.py

示例7: _do_connect

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

示例8: __init__

# 需要导入模块: import zmq [as 别名]
# 或者: from zmq import SNDTIMEO [as 别名]
def __init__(self, repPort=6868, pubPort=6869):  # 请求端口和订阅端口
        self.__rpcFunc = {}
        self.__ctx = zmq.Context()
        self.__repSocket = self.__ctx.socket(zmq.REP)
        self.__pubSocket = self.__ctx.socket(zmq.PUB)
        self.__repSocket.bind(f'tcp://*:{repPort}')
        self.__pubSocket.bind(f'tcp://*:{pubPort}')
        self.__repSocket.setsockopt(zmq.SNDTIMEO, 3000)
        self._active = False 
开发者ID:hadrianl,项目名称:huobi,代码行数:11,代码来源:rpc.py

示例9: _comm_with_timeout

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

        Args:
            socket: zmq connected socket to communicate via;
            message: message to send;

        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 status == `ok` or None;
                `time`: remote side response time.
        """
        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,代码行数:48,代码来源:base.py

示例10: _start_server

# 需要导入模块: import zmq [as 别名]
# 或者: from zmq import SNDTIMEO [as 别名]
def _start_server(self):
        """
        Configures backtrader REQ/REP server instance and starts server process.
        """

        # Ensure network resources:
        # 1. Release client-side, if any:
        if self.context:
            self.context.destroy()
            self.socket = None

        # 2. Kill any process using server port:
        cmd = "kill $( lsof -i:{} -t ) > /dev/null 2>&1".format(self.port)
        os.system(cmd)

        # Set up client channel:
        self.context = zmq.Context()
        self.socket = self.context.socket(zmq.REQ)
        self.socket.setsockopt(zmq.RCVTIMEO, self.connect_timeout * 1000)
        self.socket.setsockopt(zmq.SNDTIMEO, self.connect_timeout * 1000)
        self.socket.connect(self.network_address)

        # Configure and start server:
        self.server = BTgymServer(
            cerebro=self.engine,
            render=self.renderer,
            network_address=self.network_address,
            data_network_address=self.data_network_address,
            connect_timeout=self.connect_timeout,
            log_level=self.log_level,
            task=self.task,
        )
        self.server.daemon = False
        self.server.start()
        # Wait for server to startup:
        time.sleep(1)

        # Check connection:
        self.log.info('Server started, pinging {} ...'.format(self.network_address))

        self.server_response = self._comm_with_timeout(
            socket=self.socket,
            message={'ctrl': 'ping!'}
        )
        if self.server_response['status'] in 'ok':
            self.log.info('Server seems ready with response: <{}>'.
                           format(self.server_response['message']))

        else:
            msg = 'Server unreachable with status: <{}>.'.format(self.server_response['status'])
            self.log.error(msg)
            raise ConnectionError(msg)

        self._closed = False 
开发者ID:Kismuz,项目名称:btgym,代码行数:56,代码来源:base.py

示例11: _start_data_server

# 需要导入模块: import zmq [as 别名]
# 或者: from zmq import SNDTIMEO [as 别名]
def _start_data_server(self):
        """
        For data_master environment:
            - configures backtrader REQ/REP server instance and starts server process.

        For others:
            - establishes network connection to existing data_server.
        """
        self.data_server = None

        # Ensure network resources:
        # 1. Release client-side, if any:
        if self.data_context:
            self.data_context.destroy()
            self.data_socket = None

        # Only data_master launches/stops data_server process:
        if self.data_master:
            # 2. Kill any process using server port:
            cmd = "kill $( lsof -i:{} -t ) > /dev/null 2>&1".format(self.data_port)
            os.system(cmd)

            # Configure and start server:
            self.data_server = BTgymDataFeedServer(
                dataset=self.dataset,
                network_address=self.data_network_address,
                log_level=self.log_level,
                task=self.task
            )
            self.data_server.daemon = False
            self.data_server.start()
            # Wait for server to startup
            time.sleep(1)

        # Set up client channel:
        self.data_context = zmq.Context()
        self.data_socket = self.data_context.socket(zmq.REQ)
        self.data_socket.setsockopt(zmq.RCVTIMEO, self.connect_timeout * 1000)
        self.data_socket.setsockopt(zmq.SNDTIMEO, self.connect_timeout * 1000)
        self.data_socket.connect(self.data_network_address)

        # Check connection:
        self.log.debug('Pinging data_server at: {} ...'.format(self.data_network_address))

        self.data_server_response = self._comm_with_timeout(
            socket=self.data_socket,
            message={'ctrl': 'ping!'}
        )
        if self.data_server_response['status'] in 'ok':
            self.log.debug('Data_server seems ready with response: <{}>'.
                          format(self.data_server_response['message']))

        else:
            msg = 'Data_server unreachable with status: <{}>.'.\
                format(self.data_server_response['status'])
            self.log.error(msg)
            raise ConnectionError(msg)

        # Get info and statistic:
        self.dataset_stat, self.dataset_columns, self.data_server_pid,  self.data_lines_names = self._get_dataset_info() 
开发者ID:Kismuz,项目名称:btgym,代码行数:62,代码来源:base.py

示例12: start

# 需要导入模块: import zmq [as 别名]
# 或者: from zmq import SNDTIMEO [as 别名]
def start(self):
        context = zmq.Context()
        socket = context.socket(zmq.ROUTER)
        socket.bind(self.__bind_addr)
        socket.setsockopt(zmq.SNDTIMEO, 1000)

        app.logger.info("Entering listen loop... ")

        try:
            while True:
                msg = socket.recv_multipart()
                app.logger.debug("Received msg: {0}".format(msg))

                if len(msg) != 3:
                    error_msg = 'invalid message received: %s' % msg
                    app.logger.error(error_msg)
                    reply = [msg[0], error_msg]
                    socket.send_multipart(reply)
                    continue

                # Break out incoming message
                id = msg[0]
                operation = bytes.decode(msg[1]) if type(msg[1]) is bytes else msg[1]
                contents = json.loads(bytes.decode(msg[2]) if type(msg[2]) is bytes else msg[2])

                # Initialize the reply. Must always send back the id with ROUTER
                reply = [id]

                if operation == 'echo':
                    # Just echo back the original contents serialized back to a string
                    reply.append(self.__get_json_bytes(contents))
                elif operation == 'get_status':
                    # Get status and return
                    reply.append(self.get_status().to_json_bytes())
                elif operation == 'trigger_relay':
                    # Trigger relay
                    self.trigger_relay(contents['user_agent'], contents['login'])
                    reply.append(b'{}')
                else:
                    app.logger.error('unknown request')

                socket.send_multipart(reply)

        finally:
            app.logger.info('Closing down socket')
            socket.setsockopt(zmq.LINGER, 500)
            socket.close() 
开发者ID:nathanpjones,项目名称:GaragePi,代码行数:49,代码来源:controller.py


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