mirror of
https://github.com/wassname/ray.git
synced 2026-07-03 14:19:24 +08:00
Change timeout from milliseconds to seconds in ray.wait. (#3706)
* Change timeout from milliseconds to seconds in ray.wait. * Suppress warning. * Suppress warning. * Add prominent warning in API documentation.
This commit is contained in:
committed by
Philipp Moritz
parent
59d861281e
commit
d1e21b702e
@@ -19,7 +19,7 @@ def sleep(x):
|
||||
|
||||
|
||||
class WaitSuite(object):
|
||||
timeout = 10
|
||||
timeout = 0.01
|
||||
timer = time.time
|
||||
|
||||
def time_wait_task(self):
|
||||
@@ -35,5 +35,5 @@ class WaitSuite(object):
|
||||
def time_wait_timeout(self, timeout):
|
||||
ray.wait([sleep.remote(0.5)], timeout=timeout)
|
||||
|
||||
time_wait_timeout.params = [200, 800]
|
||||
time_wait_timeout.param_names = ["timeout_ms"]
|
||||
time_wait_timeout.params = [0.2, 0.8]
|
||||
time_wait_timeout.param_names = ["timeout"]
|
||||
|
||||
@@ -52,8 +52,8 @@ def wait(object_ids, num_returns=1, timeout=None, worker=None):
|
||||
List like of object IDs for objects that may or may not be ready.
|
||||
Note that these IDs must be unique.
|
||||
num_returns (int): The number of object IDs that should be returned.
|
||||
timeout (int): The maximum amount of time in milliseconds to wait
|
||||
before returning.
|
||||
timeout (float): The maximum amount of time in seconds to wait before
|
||||
returning.
|
||||
|
||||
Returns:
|
||||
A list of object IDs that are ready and a list of the remaining object
|
||||
@@ -61,6 +61,11 @@ def wait(object_ids, num_returns=1, timeout=None, worker=None):
|
||||
"""
|
||||
worker = ray.worker.global_worker if worker is None else worker
|
||||
if isinstance(object_ids, (tuple, np.ndarray)):
|
||||
return ray.wait(list(object_ids), num_returns, timeout, worker)
|
||||
return ray.wait(
|
||||
list(object_ids),
|
||||
num_returns=num_returns,
|
||||
timeout=timeout,
|
||||
worker=worker)
|
||||
|
||||
return ray.wait(object_ids, num_returns, timeout, worker)
|
||||
return ray.wait(
|
||||
object_ids, num_returns=num_returns, timeout=timeout, worker=worker)
|
||||
|
||||
@@ -32,7 +32,7 @@ def collect_episodes(local_evaluator,
|
||||
for a in remote_evaluators
|
||||
]
|
||||
collected, _ = ray.wait(
|
||||
pending, num_returns=len(pending), timeout=timeout_seconds * 1000)
|
||||
pending, num_returns=len(pending), timeout=timeout_seconds * 1.0)
|
||||
num_metric_batches_dropped = len(pending) - len(collected)
|
||||
|
||||
metric_lists = ray.get(collected)
|
||||
|
||||
@@ -28,7 +28,8 @@ class TaskPool(object):
|
||||
def completed(self):
|
||||
pending = list(self._tasks)
|
||||
if pending:
|
||||
ready, _ = ray.wait(pending, num_returns=len(pending), timeout=10)
|
||||
ready, _ = ray.wait(
|
||||
pending, num_returns=len(pending), timeout=0.01)
|
||||
for obj_id in ready:
|
||||
yield (self._tasks.pop(obj_id), self._objects.pop(obj_id))
|
||||
|
||||
|
||||
@@ -20,7 +20,8 @@ class Filter(object):
|
||||
"""Creates a new object with same state as self.
|
||||
|
||||
Returns:
|
||||
copy (Filter): Copy of self"""
|
||||
A copy of self.
|
||||
"""
|
||||
raise NotImplementedError
|
||||
|
||||
def sync(self, other):
|
||||
|
||||
@@ -111,7 +111,7 @@ class RayTrialExecutor(TrialExecutor):
|
||||
stop_tasks.append(trial.runner.__ray_terminate__.remote())
|
||||
# TODO(ekl) seems like wait hangs when killing actors
|
||||
_, unfinished = ray.wait(
|
||||
stop_tasks, num_returns=2, timeout=250)
|
||||
stop_tasks, num_returns=2, timeout=0.25)
|
||||
except Exception:
|
||||
logger.exception("Error stopping runner.")
|
||||
self.set_status(trial, Trial.ERROR)
|
||||
|
||||
+20
-4
@@ -2259,6 +2259,11 @@ def put(value, worker=global_worker):
|
||||
def wait(object_ids, num_returns=1, timeout=None, worker=global_worker):
|
||||
"""Return a list of IDs that are ready and a list of IDs that are not.
|
||||
|
||||
.. warning::
|
||||
|
||||
The **timeout** argument used to be in **milliseconds** (up through
|
||||
``ray==0.6.1``) and now it is in **seconds**.
|
||||
|
||||
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
|
||||
@@ -2278,8 +2283,8 @@ def wait(object_ids, num_returns=1, timeout=None, worker=global_worker):
|
||||
object_ids (List[ObjectID]): List of object IDs for objects that may or
|
||||
may not be ready. Note that these IDs must be unique.
|
||||
num_returns (int): The number of object IDs that should be returned.
|
||||
timeout (int): The maximum amount of time in milliseconds to wait
|
||||
before returning.
|
||||
timeout (float): The maximum amount of time in seconds to wait before
|
||||
returning.
|
||||
|
||||
Returns:
|
||||
A list of object IDs that are ready and a list of the remaining object
|
||||
@@ -2294,6 +2299,15 @@ def wait(object_ids, num_returns=1, timeout=None, worker=global_worker):
|
||||
raise TypeError("wait() expected a list of ObjectID, got {}".format(
|
||||
type(object_ids)))
|
||||
|
||||
if isinstance(timeout, int) and timeout != 0:
|
||||
logger.warning("The 'timeout' argument now requires seconds instead "
|
||||
"of milliseconds. This message can be suppressed by "
|
||||
"passing in a float.")
|
||||
|
||||
if timeout is not None and timeout < 0:
|
||||
raise ValueError("The 'timeout' argument must be nonnegative. "
|
||||
"Received {}".format(timeout))
|
||||
|
||||
if worker.mode != LOCAL_MODE:
|
||||
for object_id in object_ids:
|
||||
if not isinstance(object_id, ray.ObjectID):
|
||||
@@ -2328,9 +2342,11 @@ def wait(object_ids, num_returns=1, timeout=None, worker=global_worker):
|
||||
with worker.state_lock:
|
||||
current_task_id = worker.get_current_thread_task_id()
|
||||
|
||||
timeout = timeout if timeout is not None else 2**30
|
||||
timeout = timeout if timeout is not None else 10**6
|
||||
timeout_milliseconds = int(timeout * 1000)
|
||||
ready_ids, remaining_ids = worker.raylet_client.wait(
|
||||
object_ids, num_returns, timeout, False, current_task_id)
|
||||
object_ids, num_returns, timeout_milliseconds, False,
|
||||
current_task_id)
|
||||
return ready_ids, remaining_ids
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user