示例#1
0
文件: server.py 项目: fukaij/testplan
    def send(self, data, timeout=30):
        """
        Try to send the message until it either sends or hits timeout.

        :param timeout: Timeout to retry sending the message
        :type timeout: ``int``
        """
        return retry_until_timeout(exception=zmq.ZMQError,
                                   item=self._socket.send,
                                   kwargs={
                                       'data': data,
                                       'flags': zmq.NOBLOCK
                                   },
                                   timeout=timeout,
                                   raise_on_timeout=True)
示例#2
0
文件: client.py 项目: pymmrd/testplan
    def receive(self, timeout=30):
        """
        Try to receive the message until it has either been received or
        hits timeout.

        :param timeout: Timeout to retry receiving the message.
        :type timeout: ``int``

        :return: The received message.
        :rtype: ``bytes`` or ``zmq.sugar.frame.Frame`` or ``memoryview``
        """
        return retry_until_timeout(exception=zmq.ZMQError,
                                   item=self._socket.recv,
                                   kwargs={'flags': zmq.NOBLOCK},
                                   timeout=timeout, raise_on_timeout=True)
示例#3
0
文件: client.py 项目: pymmrd/testplan
    def send(self, data, timeout=30):
        """
        Try to send the message until it either sends or hits timeout.

        :param data: The content of the message.
        :type data: ``bytes`` or ``zmq.sugar.frame.Frame`` or ``memoryview``
        :param timeout: Timeout to retry sending the message.
        :type timeout: ``int``

        :return: ``None``
        :rtype: ``NoneType``
        """
        return retry_until_timeout(exception=zmq.ZMQError,
                                   item=self._socket.send,
                                   kwargs={'data': data, 'flags': zmq.NOBLOCK},
                                   timeout=timeout, raise_on_timeout=True)
示例#4
0
    def receive(self, timeout=30):
        """
        Try to send the message until it either has been received or
        hits timeout.

        :param timeout: Timeout to retry receiving the message
        :type timeout: ``int``

        :return: The received message
        :rtype: ``object`` or ``str`` or ``zmq.sugar.frame.Frame``
        """
        return retry_until_timeout(
            exception=zmq.ZMQError,
            item=self._socket.recv,
            kwargs={"flags": zmq.NOBLOCK},
            timeout=timeout,
            raise_on_timeout=True,
        )