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 excepti
(self, block=True, timeout=None)
| 152 | self.not_empty.notify() |
| 153 | |
| 154 | def get(self, block=True, timeout=None): |
| 155 | '''Remove and return an item from the queue. |
| 156 | |
| 157 | If optional args 'block' is true and 'timeout' is None (the default), |
| 158 | block if necessary until an item is available. If 'timeout' is |
| 159 | a non-negative number, it blocks at most 'timeout' seconds and raises |
| 160 | the Empty exception if no item was available within that time. |
| 161 | Otherwise ('block' is false), return an item if one is immediately |
| 162 | available, else raise the Empty exception ('timeout' is ignored |
| 163 | in that case). |
| 164 | ''' |
| 165 | with self.not_empty: |
| 166 | if not block: |
| 167 | if not self._qsize(): |
| 168 | raise Empty |
| 169 | elif timeout is None: |
| 170 | while not self._qsize(): |
| 171 | self.not_empty.wait() |
| 172 | elif timeout < 0: |
| 173 | raise ValueError("'timeout' must be a non-negative number") |
| 174 | else: |
| 175 | endtime = time() + timeout |
| 176 | while not self._qsize(): |
| 177 | remaining = endtime - time() |
| 178 | if remaining <= 0.0: |
| 179 | raise Empty |
| 180 | self.not_empty.wait(remaining) |
| 181 | item = self._get() |
| 182 | self.not_full.notify() |
| 183 | return item |
| 184 | |
| 185 | def put_nowait(self, item): |
| 186 | '''Put an item into the queue without blocking. |
no test coverage detected