'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'

def receive_messages(self, queue_name, count, wait_seconds_timeout, visibility_timeout):

    queue = self.get_queue(queue_name)
    result = []
    polling_end = (unix_time() + wait_seconds_timeout)
    while True:
        if (result or (wait_seconds_timeout and (unix_time() > polling_end))):
            break
        if (len(queue.messages) == 0):
            if (wait_seconds_timeout == 0):
                break
            import time
            time.sleep(0.001)
            continue
        for message in queue.messages:
            if (not message.visible):
                continue
            message.mark_received(visibility_timeout=visibility_timeout)
            result.append(message)
            if (len(result) >= count):
                break
    return result
