Refactor if/elif chain for clarity and speed
This commit is contained in:
parent
f7bd964fb5
commit
ae138cbfbb
21
Lib/Queue.py
21
Lib/Queue.py
|
@ -102,18 +102,17 @@ class Queue:
|
||||||
"""
|
"""
|
||||||
self.not_full.acquire()
|
self.not_full.acquire()
|
||||||
try:
|
try:
|
||||||
if not block:
|
if self.maxsize > 0:
|
||||||
if self.maxsize > 0 and self._qsize() == self.maxsize:
|
if not block:
|
||||||
raise Full
|
if self._qsize() == self.maxsize:
|
||||||
elif timeout is None:
|
raise Full
|
||||||
if self.maxsize > 0:
|
elif timeout is None:
|
||||||
while self._qsize() == self.maxsize:
|
while self._qsize() == self.maxsize:
|
||||||
self.not_full.wait()
|
self.not_full.wait()
|
||||||
else:
|
elif timeout < 0:
|
||||||
if timeout < 0:
|
|
||||||
raise ValueError("'timeout' must be a positive number")
|
raise ValueError("'timeout' must be a positive number")
|
||||||
endtime = _time() + timeout
|
else:
|
||||||
if self.maxsize > 0:
|
endtime = _time() + timeout
|
||||||
while self._qsize() == self.maxsize:
|
while self._qsize() == self.maxsize:
|
||||||
remaining = endtime - _time()
|
remaining = endtime - _time()
|
||||||
if remaining <= 0.0:
|
if remaining <= 0.0:
|
||||||
|
@ -152,9 +151,9 @@ class Queue:
|
||||||
elif timeout is None:
|
elif timeout is None:
|
||||||
while not self._qsize():
|
while not self._qsize():
|
||||||
self.not_empty.wait()
|
self.not_empty.wait()
|
||||||
|
elif timeout < 0:
|
||||||
|
raise ValueError("'timeout' must be a positive number")
|
||||||
else:
|
else:
|
||||||
if timeout < 0:
|
|
||||||
raise ValueError("'timeout' must be a positive number")
|
|
||||||
endtime = _time() + timeout
|
endtime = _time() + timeout
|
||||||
while not self._qsize():
|
while not self._qsize():
|
||||||
remaining = endtime - _time()
|
remaining = endtime - _time()
|
||||||
|
|
Loading…
Reference in New Issue