Skip to content

Commit

Permalink
[GH-29]Fix cpu bound when queue is empty (#30)
Browse files Browse the repository at this point in the history
the event is not cleared when queue is empty which
cause high cpu consumption
  • Loading branch information
peter-wangxu authored Oct 31, 2017
1 parent d26561e commit 71ded7c
Showing 1 changed file with 2 additions and 0 deletions.
2 changes: 2 additions & 0 deletions persistqueue/sqlqueue.py
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,7 @@ def get(self, block=True, timeout=None):
# block until a put event.
pickled = self._pop()
while not pickled:
self.put_event.clear()
self.put_event.wait(TICK_FOR_WAIT)
pickled = self._pop()
elif timeout < 0:
Expand All @@ -75,6 +76,7 @@ def get(self, block=True, timeout=None):
endtime = _time.time() + timeout
pickled = self._pop()
while not pickled:
self.put_event.clear()
remaining = endtime - _time.time()
if remaining <= 0.0:
raise Empty
Expand Down

0 comments on commit 71ded7c

Please sign in to comment.