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 non-negative number, it blocks at most 'timeout' seconds and raises the Empty exception if
(self, block=True, timeout=None)
| 175 | self.not_empty.notify() |
| 176 | |
| 177 | def get(self, block=True, timeout=None): |
| 178 | '''Remove and return an item from the queue. |
| 179 | |
| 180 | If optional args 'block' is true and 'timeout' is None (the default), |
| 181 | block if necessary until an item is available. If 'timeout' is |
| 182 | a non-negative number, it blocks at most 'timeout' seconds and raises |
| 183 | the Empty exception if no item was available within that time. |
| 184 | Otherwise ('block' is false), return an item if one is immediately |
| 185 | available, else raise the Empty exception ('timeout' is ignored |
| 186 | in that case). |
| 187 | |
| 188 | Raises ShutDown if the queue has been shut down and is empty, |
| 189 | or if the queue has been shut down immediately. |
| 190 | ''' |
| 191 | with self.not_empty: |
| 192 | if self.is_shutdown and not self._qsize(): |
| 193 | raise ShutDown |
| 194 | if not block: |
| 195 | if not self._qsize(): |
| 196 | raise Empty |
| 197 | elif timeout is None: |
| 198 | while not self._qsize(): |
| 199 | self.not_empty.wait() |
| 200 | if self.is_shutdown and not self._qsize(): |
| 201 | raise ShutDown |
| 202 | elif timeout < 0: |
| 203 | raise ValueError("'timeout' must be a non-negative number") |
| 204 | else: |
| 205 | endtime = time() + timeout |
| 206 | while not self._qsize(): |
| 207 | remaining = endtime - time() |
| 208 | if remaining <= 0.0: |
| 209 | raise Empty |
| 210 | self.not_empty.wait(remaining) |
| 211 | if self.is_shutdown and not self._qsize(): |
| 212 | raise ShutDown |
| 213 | item = self._get() |
| 214 | self.not_full.notify() |
| 215 | return item |
| 216 | |
| 217 | def put_nowait(self, item): |
| 218 | '''Put an item into the queue without blocking. |
no test coverage detected