def receive_messages(self, queue_name, count, wait_seconds_timeout, visibility_timeout):
        """
        Attempt to retrieve visible messages from a queue.

        If a message was read by client and not deleted it is considered to be
        "inflight" and cannot be read. We make attempts to obtain ``count``
        messages but we may return less if messages are in-flight or there
        are simple not enough messages in the queue.

        :param string queue_name: The name of the queue to read from.
        :param int count: The maximum amount of messages to retrieve.
        :param int visibility_timeout: The number of seconds the message should remain invisible to other queue readers.
        :param int wait_seconds_timeout:  The duration (in seconds) for which the call waits for a message to arrive in
         the queue before returning. If a message is available, the call returns sooner than WaitTimeSeconds
        """
        queue = self.get_queue(queue_name)
        result = []
        previous_result_count = len(result)

        polling_end = unix_time() + wait_seconds_timeout

        # queue.messages only contains visible messages
        while True:

            if result or (wait_seconds_timeout and unix_time() > polling_end):
                break

            messages_to_dlq = []

            for message in queue.messages:
                if not message.visible:
                    continue

                if message in queue.pending_messages:
                    # The message is pending but is visible again, so the
                    # consumer must have timed out.
                    queue.pending_messages.remove(message)

                if message.group_id and queue.fifo_queue:
                    if message.group_id in queue.pending_message_groups:
                        # There is already one active message with the same
                        # group, so we cannot deliver this one.
                        continue

                queue.pending_messages.add(message)

                if queue.dead_letter_queue is not None and message.approximate_receive_count >= queue.redrive_policy['maxReceiveCount']:
                    messages_to_dlq.append(message)
                    continue

                message.mark_received(
                    visibility_timeout=visibility_timeout
                )
                result.append(message)
                if len(result) >= count:
                    break

            for message in messages_to_dlq:
                queue._messages.remove(message)
                queue.dead_letter_queue.add_message(message)

            if previous_result_count == len(result):
                if wait_seconds_timeout == 0:
                    # There is timeout and we have added no additional results,
                    # so break to avoid an infinite loop.
                    break

                import time
                time.sleep(0.01)
                continue

            previous_result_count = len(result)

        return result
def receive_messages ( self , queue_name , count , wait_seconds_timeout , visibility_timeout ) : queue = self . get_queue ( queue_name ) result = [ ] previous_result_count = len ( result ) polling_end = unix_time ( ) + wait_seconds_timeout while True : if result or ( wait_seconds_timeout and unix_time ( ) > polling_end ) : break messages_to_dlq = [ ] for message in queue . messages : if not message . visible : continue if message in queue . pending_messages : queue . pending_messages . remove ( message ) if message . group_id and queue . fifo_queue : if message . group_id in queue . pending_message_groups : continue queue . pending_messages . add ( message ) if queue . dead_letter_queue is not None and message . approximate_receive_count >= queue . redrive_policy [ 'maxReceiveCount' ] : messages_to_dlq . append ( message ) continue message . mark_received ( visibility_timeout = visibility_timeout ) result . append ( message ) if len ( result ) >= count : break for message in messages_to_dlq : queue . _messages . remove ( message ) queue . dead_letter_queue . add_message ( message ) if previous_result_count == len ( result ) : if wait_seconds_timeout == 0 : break import time time . sleep ( 0.01 ) continue previous_result_count = len ( result ) return result
Attempt to retrieve visible messages from a queue.

        If a message was read by client and not deleted it is considered to be
        "inflight" and cannot be read. We make attempts to obtain ``count``
        messages but we may return less if messages are in-flight or there
        are simple not enough messages in the queue.

        :param string queue_name: The name of the queue to read from.
        :param int count: The maximum amount of messages to retrieve.
        :param int visibility_timeout: The number of seconds the message should remain invisible to other queue readers.
        :param int wait_seconds_timeout:  The duration (in seconds) for which the call waits for a message to arrive in
         the queue before returning. If a message is available, the call returns sooner than WaitTimeSeconds