mirror of
https://github.com/vale981/ray
synced 2025-03-06 10:31:39 -05:00
Add a nicer warning message when you pass the wrong thing to ray.wait() (#1239)
* add warnings * fix python mode * Small changes and add tests. * Fix test failure.
This commit is contained in:
parent
c1496b8111
commit
37831ae0c3
3 changed files with 26 additions and 1 deletions
|
@ -156,7 +156,7 @@ class TrialRunner(object):
|
|||
# have been lost
|
||||
|
||||
def _process_events(self):
|
||||
[result_id], _ = ray.wait(self._running.keys())
|
||||
[result_id], _ = ray.wait(list(self._running.keys()))
|
||||
trial = self._running[result_id]
|
||||
del self._running[result_id]
|
||||
try:
|
||||
|
|
|
@ -2223,6 +2223,22 @@ def wait(object_ids, num_returns=1, timeout=None, worker=global_worker):
|
|||
A list of object IDs that are ready and a list of the remaining object
|
||||
IDs.
|
||||
"""
|
||||
|
||||
if isinstance(object_ids, ray.local_scheduler.ObjectID):
|
||||
raise TypeError(
|
||||
"wait() expected a list of ObjectID, got a single ObjectID")
|
||||
|
||||
if not isinstance(object_ids, list):
|
||||
raise TypeError("wait() expected a list of ObjectID, got {}".format(
|
||||
type(object_ids)))
|
||||
|
||||
if worker.mode != PYTHON_MODE:
|
||||
for object_id in object_ids:
|
||||
if not isinstance(object_id, ray.local_scheduler.ObjectID):
|
||||
raise TypeError(
|
||||
"wait() expected a list of ObjectID, "
|
||||
"got list containing {}".format(type(object_id)))
|
||||
|
||||
check_connected(worker)
|
||||
with log_span("ray:wait", worker=worker):
|
||||
check_main_thread()
|
||||
|
|
|
@ -749,6 +749,15 @@ class APITest(unittest.TestCase):
|
|||
self.assertEqual(ready_ids, [])
|
||||
self.assertEqual(remaining_ids, [])
|
||||
|
||||
# Verify that incorrect usage raises a TypeError.
|
||||
x = ray.put(1)
|
||||
with self.assertRaises(TypeError):
|
||||
ray.wait(x)
|
||||
with self.assertRaises(TypeError):
|
||||
ray.wait(1)
|
||||
with self.assertRaises(TypeError):
|
||||
ray.wait([1])
|
||||
|
||||
def testMultipleWaitsAndGets(self):
|
||||
# It is important to use three workers here, so that the three tasks
|
||||
# launched in this experiment can run at the same time.
|
||||
|
|
Loading…
Add table
Reference in a new issue