ray.wait#

ray.wait(ray_waitables: List[ray._raylet.ObjectRef | ray._raylet.ObjectRefGenerator], *, num_returns: int = 1, timeout: float | None = None, fetch_local: bool = True) Tuple[List[ray._raylet.ObjectRef | ray._raylet.ObjectRefGenerator], List[ray._raylet.ObjectRef | ray._raylet.ObjectRefGenerator]][source]#

Return a list of IDs that are ready and a list of IDs that are not.

If timeout is set, the function returns either when the requested number of IDs are ready or when the timeout is reached, whichever occurs first. If it is not set, the function simply waits until that number of objects is ready and returns that exact number of object refs.

ray_waitables is a list of ObjectRef and ObjectRefGenerator.

The method returns two lists, ready and unready ray_waitables.

ObjectRef:

object refs that correspond to objects that are available in the object store are in the first list. The rest of the object refs are in the second list.

ObjectRefGenerator:

Generators whose next reference (that will be obtained via next(generator)) has a corresponding object available in the object store are in the first list. All other generators are placed in the second list.

Ordering of the input list of ray_waitables is preserved. That is, if A precedes B in the input list, and both are in the ready list, then A will precede B in the ready list. This also holds true if A and B are both in the remaining list.

This method will issue a warning if it’s running inside an async context. Instead of ray.wait(ray_waitables), you can use await asyncio.wait(ray_waitables).

Related patterns and anti-patterns:

Parameters:
  • ray_waitables – List of ObjectRef or ObjectRefGenerator for objects that may or may not be ready. Note that these must be unique.

  • num_returns – The number of ray_waitables that should be returned.

  • timeout – The maximum amount of time in seconds to wait before returning.

  • fetch_local – If True, wait for the object to be downloaded onto the local node before returning it as ready. If the ray_waitable is a generator, it will wait until the next object in the generator is downloaed. If False, ray.wait() will not trigger fetching of objects to the local node and will return immediately once the object is available anywhere in the cluster.

Returns:

A list of object refs that are ready and a list of the remaining object IDs.