Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 611eaf0

Browse files
committed
Document the suggested alternative to emtpy() and full().
1 parent 66913e2 commit 611eaf0

File tree

1 file changed

+19
-2
lines changed

1 file changed

+19
-2
lines changed

Lib/queue.py

Lines changed: 19 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -91,14 +91,31 @@ def qsize(self):
9191
return n
9292

9393
def empty(self):
94-
"""Return True if the queue is empty, False otherwise (not reliable!)."""
94+
"""Return True if the queue is empty, False otherwise (not reliable!).
95+
96+
This method is likely to be removed at some point. Use qsize() == 0
97+
as a direct substitute, but be aware that either approach risks a race
98+
condition where a queue can grow before the result of empty() or
99+
qsize() can be used.
100+
101+
To create code that needs to wait for all queued tasks to be
102+
completed, the preferred technique is to use the join() method.
103+
104+
"""
95105
self.mutex.acquire()
96106
n = not self._qsize()
97107
self.mutex.release()
98108
return n
99109

100110
def full(self):
101-
"""Return True if the queue is full, False otherwise (not reliable!)."""
111+
"""Return True if the queue is full, False otherwise (not reliable!).
112+
113+
This method is likely to be removed at some point. Use qsize() == n
114+
as a direct substitute, but be aware that either approach risks a race
115+
condition where a queue can shrink before the result of full() or
116+
qsize() can be used.
117+
118+
"""
102119
self.mutex.acquire()
103120
n = 0 < self.maxsize == self._qsize()
104121
self.mutex.release()

0 commit comments

Comments
 (0)