Skip to content
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
54 changes: 54 additions & 0 deletions python/ray/tests/test_basic.py
Original file line number Diff line number Diff line change
Expand Up @@ -112,6 +112,60 @@ def method(self):
assert ray.get([id1, id2, id3, id4]) == [0, 1, "test", 2]


def test_invalid_arguments(shutdown_only):
ray.init(num_cpus=2)

for opt in [np.random.randint(-100, -1), np.random.uniform(0, 1)]:
with pytest.raises(
ValueError,
match="The keyword 'num_return_vals' only accepts 0 or a"
" positive integer"):

@ray.remote(num_return_vals=opt)
def g1():
return 1

for opt in [np.random.randint(-100, -2), np.random.uniform(0, 1)]:
with pytest.raises(
ValueError,
match="The keyword 'max_retries' only accepts 0, -1 or a"
" positive integer"):

@ray.remote(max_retries=opt)
def g2():
return 1

for opt in [np.random.randint(-100, -1), np.random.uniform(0, 1)]:
with pytest.raises(
ValueError,
match="The keyword 'max_calls' only accepts 0 or a positive"
" integer"):

@ray.remote(max_calls=opt)
def g3():
return 1

for opt in [np.random.randint(-100, -2), np.random.uniform(0, 1)]:
with pytest.raises(
ValueError,
match="The keyword 'max_restarts' only accepts -1, 0 or a"
" positive integer"):

@ray.remote(max_restarts=opt)
class A1:
x = 1

for opt in [np.random.randint(-100, -2), np.random.uniform(0, 1)]:
with pytest.raises(
ValueError,
match="The keyword 'max_task_retries' only accepts -1, 0 or a"
" positive integer"):

@ray.remote(max_task_retries=opt)
class A2:
x = 1


def test_many_fractional_resources(shutdown_only):
ray.init(num_cpus=2, num_gpus=2, resources={"Custom": 2})

Expand Down
27 changes: 25 additions & 2 deletions python/ray/worker.py
Original file line number Diff line number Diff line change
Expand Up @@ -1799,7 +1799,21 @@ def decorator(function_or_class):
if max_task_retries is not None:
raise ValueError("The keyword 'max_task_retries' is not "
"allowed for remote functions.")

if num_return_vals is not None and (not isinstance(
num_return_vals, int) or num_return_vals < 0):
raise ValueError(
"The keyword 'num_return_vals' only accepts 0 or a"
" positive integer")
if max_retries is not None and (not isinstance(max_retries, int)
or max_retries < -1):
raise ValueError(
"The keyword 'max_retries' only accepts 0, -1 or a"
" positive integer")
if max_calls is not None and (not isinstance(max_calls, int)
or max_calls < 0):
raise ValueError(
"The keyword 'max_calls' only accepts 0 or a positive"
" integer")
return ray.remote_function.RemoteFunction(
Language.PYTHON, function_or_class, None, num_cpus, num_gpus,
memory, object_store_memory, resources, num_return_vals,
Expand All @@ -1813,7 +1827,16 @@ def decorator(function_or_class):
if max_calls is not None:
raise TypeError("The keyword 'max_calls' is not "
"allowed for actors.")

if max_restarts is not None and (not isinstance(max_restarts, int)
or max_restarts < -1):
raise ValueError(
"The keyword 'max_restarts' only accepts -1, 0 or a"
" positive integer")
if max_task_retries is not None and (not isinstance(
max_task_retries, int) or max_task_retries < -1):
raise ValueError(
"The keyword 'max_task_retries' only accepts -1, 0 or a"
" positive integer")
return ray.actor.make_actor(function_or_class, num_cpus, num_gpus,
memory, object_store_memory, resources,
max_restarts, max_task_retries)
Expand Down