tornado.queues – Queues for coroutines

4.2 新版功能.

exception tornado.queues.QueueEmpty[源代码]

Raised by Queue.get_nowait when the queue has no items.

exception tornado.queues.QueueFull[源代码]

Raised by Queue.put_nowait when a queue is at its maximum size.

class tornado.queues.Queue(maxsize=0)[源代码]

Coordinate producer and consumer coroutines.

If maxsize is 0 (the default) the queue size is unbounded.

maxsize

Number of items allowed in the queue.

qsize()[源代码]

Number of items in the queue.

put(item, timeout=None)[源代码]

Put an item into the queue, perhaps waiting until there is room.

Returns a Future, which raises tornado.gen.TimeoutError after a timeout.

put_nowait(item)[源代码]

Put an item into the queue without blocking.

If no free slot is immediately available, raise QueueFull.

get(timeout=None)[源代码]

Remove and return an item from the queue.

Returns a Future which resolves once an item is available, or raises tornado.gen.TimeoutError after a timeout.

get_nowait()[源代码]

Remove and return an item from the queue without blocking.

Return an item if one is immediately available, else raise QueueEmpty.

task_done()[源代码]

Indicate that a formerly enqueued task is complete.

Used by queue consumers. For each get used to fetch a task, a subsequent call to task_done tells the queue that the processing on the task is complete.

If a join is blocking, it resumes when all items have been processed; that is, when every put is matched by a task_done.

Raises ValueError if called more times than put.

join(timeout=None)[源代码]

Block until all items in the queue are processed.

Returns a Future, which raises tornado.gen.TimeoutError after a timeout.

class tornado.queues.PriorityQueue(maxsize=0)[源代码]

A Queue that retrieves entries in priority order, lowest first.

Entries are typically tuples like (priority number, data).

class tornado.queues.LifoQueue(maxsize=0)[源代码]

A Queue that retrieves the most recently put items first.