Remove and return an item from the queue. Returns an awaitable which resolves once an item is available, or raises `tornado.util.TimeoutError` after a timeout. ``timeout`` may be a number denoting a time (on the same scale as `tornado.ioloop.IOLoop.time`, normally `
(
self, timeout: Optional[Union[float, datetime.timedelta]] = None
)
| 223 | self.__put_internal(item) |
| 224 | |
| 225 | def get( |
| 226 | self, timeout: Optional[Union[float, datetime.timedelta]] = None |
| 227 | ) -> Awaitable[_T]: |
| 228 | """Remove and return an item from the queue. |
| 229 | |
| 230 | Returns an awaitable which resolves once an item is available, or raises |
| 231 | `tornado.util.TimeoutError` after a timeout. |
| 232 | |
| 233 | ``timeout`` may be a number denoting a time (on the same |
| 234 | scale as `tornado.ioloop.IOLoop.time`, normally `time.time`), or a |
| 235 | `datetime.timedelta` object for a deadline relative to the |
| 236 | current time. |
| 237 | |
| 238 | .. note:: |
| 239 | |
| 240 | The ``timeout`` argument of this method differs from that |
| 241 | of the standard library's `queue.Queue.get`. That method |
| 242 | interprets numeric values as relative timeouts; this one |
| 243 | interprets them as absolute deadlines and requires |
| 244 | ``timedelta`` objects for relative timeouts (consistent |
| 245 | with other timeouts in Tornado). |
| 246 | |
| 247 | """ |
| 248 | future = Future() # type: Future[_T] |
| 249 | try: |
| 250 | future.set_result(self.get_nowait()) |
| 251 | except QueueEmpty: |
| 252 | self._getters.append(future) |
| 253 | _set_timeout(future, timeout) |
| 254 | return future |
| 255 | |
| 256 | def get_nowait(self) -> _T: |
| 257 | """Remove and return an item from the queue without blocking. |