class ray.util.queue.Queue(maxsize: int = 0, actor_options: Optional[Dict] = None)[source]#

Bases: object

A first-in, first-out queue implementation on Ray.

The behavior and use cases are similar to those of the asyncio.Queue class.

Features both sync and async put and get methods. Provides the option to block until space is available when calling put on a full queue, or to block until items are available when calling get on an empty queue.

Optionally supports batched put and get operations to minimize serialization overhead.

  • maxsize (optional, int) – maximum size of the queue. If zero, size is unbounded.

  • actor_options (optional, Dict) – Dictionary of options to pass into the QueueActor during creation. These are directly passed into QueueActor.options(…). This could be useful if you need to pass in custom resource requirements, for example.


from ray.util.queue import Queue
q = Queue()
items = list(range(10))
for item in items:
for item in items:
    assert item == q.get()
# Create Queue with the underlying actor reserving 1 CPU.
q = Queue(actor_options={"num_cpus": 1})

PublicAPI (beta): This API is in beta and may change before becoming stable.



Whether the queue is empty.


Whether the queue is full.

get([block, timeout])

Gets an item from the queue.

get_async([block, timeout])

Gets an item from the queue.


Equivalent to get(block=False).


Gets items from the queue and returns them in a list in order.

put(item[, block, timeout])

Adds an item to the queue.

put_async(item[, block, timeout])

Adds an item to the queue.


Equivalent to put(item, block=False).


Takes in a list of items and puts them into the queue in order.


The size of the queue.

shutdown([force, grace_period_s])

Terminates the underlying QueueActor.


The size of the queue.