ray.util.queue.Queue#
- class ray.util.queue.Queue(maxsize: int = 0, actor_options: Dict | None = None)[source]#
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.
- Parameters:
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.
Examples
from ray.util.queue import Queue q = Queue() items = list(range(10)) for item in items: q.put(item) 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.
Methods
Whether the queue is empty.
Whether the queue is full.
Gets an item from the queue.
Gets an item from the queue.
Equivalent to get(block=False).
Gets items from the queue and returns them in a list in order.
Adds an item to the queue.
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.
Terminates the underlying QueueActor.
The size of the queue.