Skip to content

Commit

Permalink
Add a nicer warning message when you pass the wrong thing to ray.wait…
Browse files Browse the repository at this point in the history
…() (#1239)

* add warnings

* fix python mode

* Small changes and add tests.

* Fix test failure.
  • Loading branch information
ericl authored and robertnishihara committed Nov 28, 2017
1 parent c1496b8 commit 37831ae
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 1 deletion.
2 changes: 1 addition & 1 deletion python/ray/tune/trial_runner.py
Original file line number Diff line number Diff line change
Expand Up @@ -156,7 +156,7 @@ def _launch_trial(self):
# 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:
Expand Down
16 changes: 16 additions & 0 deletions python/ray/worker.py
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down
9 changes: 9 additions & 0 deletions test/runtest.py
Original file line number Diff line number Diff line change
Expand Up @@ -749,6 +749,15 @@ def f(delay):
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.
Expand Down

0 comments on commit 37831ae

Please sign in to comment.