diff options
author | Raymond Hettinger <python@rcn.com> | 2008-01-15 20:42:00 (GMT) |
---|---|---|
committer | Raymond Hettinger <python@rcn.com> | 2008-01-15 20:42:00 (GMT) |
commit | ae138cbfbbfb376917fd29abb6724d56ba5fc081 (patch) | |
tree | 79b21fb5bde50d4c89e0f32e5c68f5ac15ad8d18 /Lib/Queue.py | |
parent | f7bd964fb5364e6cf8feac5f088e214b4f4e9478 (diff) | |
download | cpython-ae138cbfbbfb376917fd29abb6724d56ba5fc081.zip cpython-ae138cbfbbfb376917fd29abb6724d56ba5fc081.tar.gz cpython-ae138cbfbbfb376917fd29abb6724d56ba5fc081.tar.bz2 |
Refactor if/elif chain for clarity and speed
Diffstat (limited to 'Lib/Queue.py')
-rw-r--r-- | Lib/Queue.py | 21 |
1 files changed, 10 insertions, 11 deletions
diff --git a/Lib/Queue.py b/Lib/Queue.py index 726cf3e..f8aa0af 100644 --- a/Lib/Queue.py +++ b/Lib/Queue.py @@ -102,18 +102,17 @@ class Queue: """ self.not_full.acquire() try: - if not block: - if self.maxsize > 0 and self._qsize() == self.maxsize: - raise Full - elif timeout is None: - if self.maxsize > 0: + if self.maxsize > 0: + if not block: + if self._qsize() == self.maxsize: + raise Full + elif timeout is None: while self._qsize() == self.maxsize: self.not_full.wait() - else: - if timeout < 0: + elif timeout < 0: raise ValueError("'timeout' must be a positive number") - endtime = _time() + timeout - if self.maxsize > 0: + else: + endtime = _time() + timeout while self._qsize() == self.maxsize: remaining = endtime - _time() if remaining <= 0.0: @@ -152,9 +151,9 @@ class Queue: elif timeout is None: while not self._qsize(): self.not_empty.wait() + elif timeout < 0: + raise ValueError("'timeout' must be a positive number") else: - if timeout < 0: - raise ValueError("'timeout' must be a positive number") endtime = _time() + timeout while not self._qsize(): remaining = endtime - _time() |