Remove and return an item from the queue. If optional args `block` is True and `timeout` is None (the default), block if necessary until an item is available. If `timeout` is a positive number, it blocks at most `timeout` seconds and raises the ``Empty`` exception if
(self, block: bool = True, timeout: Optional[float] = None)
| 169 | return self.put(item, False) |
| 170 | |
| 171 | def get(self, block: bool = True, timeout: Optional[float] = None) -> _T: |
| 172 | """Remove and return an item from the queue. |
| 173 | |
| 174 | If optional args `block` is True and `timeout` is None (the |
| 175 | default), block if necessary until an item is available. If |
| 176 | `timeout` is a positive number, it blocks at most `timeout` |
| 177 | seconds and raises the ``Empty`` exception if no item was |
| 178 | available within that time. Otherwise (`block` is false), |
| 179 | return an item if one is immediately available, else raise the |
| 180 | ``Empty`` exception (`timeout` is ignored in that case). |
| 181 | |
| 182 | """ |
| 183 | with self.not_empty: |
| 184 | if not block: |
| 185 | if self._empty(): |
| 186 | raise Empty |
| 187 | elif timeout is None: |
| 188 | while self._empty(): |
| 189 | self.not_empty.wait() |
| 190 | else: |
| 191 | if timeout < 0: |
| 192 | raise ValueError("'timeout' must be a positive number") |
| 193 | endtime = _time() + timeout |
| 194 | while self._empty(): |
| 195 | remaining = endtime - _time() |
| 196 | if remaining <= 0.0: |
| 197 | raise Empty |
| 198 | self.not_empty.wait(remaining) |
| 199 | item = self._get() |
| 200 | self.not_full.notify() |
| 201 | return item |
| 202 | |
| 203 | def get_nowait(self) -> _T: |
| 204 | """Remove and return an item from the queue without blocking. |