yr.wait

Contents

yr.wait#

yr.wait(obj_refs: ObjectRef | List[ObjectRef], wait_num: int | None = None, timeout: int | None = None) Tuple[List[ObjectRef], List[ObjectRef]][source]#

Wait for the value of the object in the data system to be ready based on the object’s key. The interface call will block until the value of the object is computed.

Note

The results returned each time may differ because the order of completion of invoke is not guaranteed.

Parameters:
  • object_refs (list) – Data saved to the data system.

  • wait_num (int, optional) – The minimum number of objects to wait for. It defaults to len(obj_refs). The value should not exceed the length of obj_refs.

  • timeout (int, optional) – The timeout in seconds. Note that if the default value None is used, it will wait indefinitely, with the actual maximum wait time limited by the wait factors in get.

Returns:

the first list contains the completed requests; the second list contains the uncompleted requests. Data type is tuple[list, list].

Return type:

Returns two lists

Raises:
  • TypeError – If the input parameter type is incorrect.

  • ValueError – If the input parameter is incorrect.

Examples

>>> import yr
>>> import time
>>>
>>> yr.init()
>>>
>>> @yr.invoke
... def demo(a):
...     time.sleep(a)
...     return "sleep:", a
...
>>> res = [demo.invoke(i) for i in range(4)]
>>>
>>> wait_num = 3
>>> timeout = 10
>>> result = yr.wait(res, wait_num, timeout)
>>> print("ready_list  = ", result[0], "unready_list = ", result[1])
>>> print(yr.get(result[0]))
[('sleep:', 0), ('sleep:', 1)]
>>>
>>> yr.finalize()