(self, expected_packet_choices, timeout=None,
                   assert_return_success=True)
Process packets until a packet of one of the expected types is found.

        expected_packet_choices -- a list of BGLib.PacketType.xxxxx. Upon
                                   processing a packet of a type contained in
                                   the list, this function will return.
        timeout -- maximum time in seconds to process packets.
        assert_return_success -- raise an exception if the return code from a
            matched message is non-zero.

        Raises an ExpectedResponseTimeout if one of the expected responses is
            not receiving withint the time limit.
Process packets until a packet of one of the expected types is found.
Process packets until a packet of one of the expected types is found .
def expect_any(self, expected_packet_choices, timeout=None,
                   assert_return_success=True):
        """
        Process packets until a packet of one of the expected types is found.

        expected_packet_choices -- a list of BGLib.PacketType.xxxxx. Upon
                                   processing a packet of a type contained in
                                   the list, this function will return.
        timeout -- maximum time in seconds to process packets.
        assert_return_success -- raise an exception if the return code from a
            matched message is non-zero.

        Raises an ExpectedResponseTimeout if one of the expected responses is
            not receiving withint the time limit.
        """
        timeout = timeout or 1
        log.debug("Expecting a response of one of %s within %fs",
                  expected_packet_choices, timeout or 0)

        start_time = None
        if timeout is not None:
            start_time = time.time()

        while True:
            packet = None
            try:
                packet = self._receiver_queue.get(
                    timeout=self._receive_queue_timeout)
            except queue.Empty:
                if timeout is not None:
                    if _timed_out(start_time, timeout):
                        exc = ExpectedResponseTimeout(
                            expected_packet_choices, timeout)
                        exc.__cause__ = None
                        raise exc
                    continue

            if packet is None:
                raise ExpectedResponseTimeout(expected_packet_choices, timeout)

            try:
                packet_type, response = self._lib.decode_packet(packet)
            except bglib.UnknownMessageType:
                log.warn("Ignoring message decode failure", exc_info=True)
                continue

            return_code = response.get('result', 0)
            log.debug("Received a %s packet: %s",
                      packet_type, get_return_message(return_code))

            if packet_type in self._packet_handlers:
                self._packet_handlers[packet_type](response)

            if packet_type in expected_packet_choices:
                return packet_type, response
def expect_any ( self , expected_packet_choices , timeout = None , assert_return_success = True ) : timeout = timeout or 1 log . debug ( "Expecting a response of one of %s within %fs" , expected_packet_choices , timeout or 0 ) start_time = None if timeout is not None : start_time = time . time ( ) while True : packet = None try : packet = self . _receiver_queue . get ( timeout = self . _receive_queue_timeout ) except queue . Empty : if timeout is not None : if _timed_out ( start_time , timeout ) : exc = ExpectedResponseTimeout ( expected_packet_choices , timeout ) exc . __cause__ = None raise exc continue if packet is None : raise ExpectedResponseTimeout ( expected_packet_choices , timeout ) try : packet_type , response = self . _lib . decode_packet ( packet ) except bglib . UnknownMessageType : log . warn ( "Ignoring message decode failure" , exc_info = True ) continue return_code = response . get ( 'result' , 0 ) log . debug ( "Received a %s packet: %s" , packet_type , get_return_message ( return_code ) ) if packet_type in self . _packet_handlers : self . _packet_handlers [ packet_type ] ( response ) if packet_type in expected_packet_choices : return packet_type , response