Skip to content

Commit

Permalink
Merge pull request #871 from mike-lerch/cpu-100-empty-queue
Browse files Browse the repository at this point in the history
Prevent 100% cpu usage while SQS long polling on an empty queue
  • Loading branch information
spulec committed Mar 17, 2017
2 parents a5da348 + 83084bf commit 042524f
Showing 1 changed file with 5 additions and 0 deletions.
5 changes: 5 additions & 0 deletions moto/sqs/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -289,6 +289,11 @@ def receive_messages(self, queue_name, count, wait_seconds_timeout, visibility_t

# queue.messages only contains visible messages
while True:
if len(queue.messages) == 0:
import time
time.sleep(0.001)
continue

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

0 comments on commit 042524f

Please sign in to comment.