Skip to content

Commit b7bd482

Browse files
authored
Merge pull request peterhinch#42 from dbadrian/feature/queue_full_check_optimization
Full check optimization in v3 queue
2 parents c7f07e1 + a16285e commit b7bd482

File tree

1 file changed

+5
-9
lines changed

1 file changed

+5
-9
lines changed

v3/primitives/queue.py

Lines changed: 5 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -48,15 +48,15 @@ def _put(self, val):
4848
self._queue.append(val)
4949

5050
async def put(self, val): # Usage: await queue.put(item)
51-
if self.qsize() >= self.maxsize and self.maxsize:
51+
if self.full():
5252
# Queue full
5353
self._evget.clear()
5454
await self._evget.wait()
5555
# Task(s) waiting to get from queue, schedule first Task
5656
self._put(val)
5757

5858
def put_nowait(self, val): # Put an item into the queue without blocking.
59-
if self.maxsize and self.qsize() >= self.maxsize:
59+
if self.full():
6060
raise QueueFull()
6161
self._put(val)
6262

@@ -67,10 +67,6 @@ def empty(self): # Return True if the queue is empty, False otherwise.
6767
return len(self._queue) == 0
6868

6969
def full(self): # Return True if there are maxsize items in the queue.
70-
# Note: if the Queue was initialized with maxsize=0 (the default),
71-
# then full() is never True.
72-
73-
if self.maxsize <= 0:
74-
return False
75-
else:
76-
return self.qsize() >= self.maxsize
70+
# Note: if the Queue was initialized with maxsize=0 (the default) or
71+
# any negative number, then full() is never True.
72+
return self.maxsize > 0 and self.qsize() >= self.maxsize

0 commit comments

Comments
 (0)