mirror of
https://github.com/wassname/ray.git
synced 2026-06-28 07:34:30 +08:00
[core] Enabling Remote Task Cancelation (#8225)
This commit is contained in:
@@ -228,5 +228,31 @@ def test_fast(shutdown_only, use_force):
|
||||
assert isinstance(e, valid_exceptions(use_force))
|
||||
|
||||
|
||||
@pytest.mark.parametrize("use_force", [True, False])
|
||||
def test_remote_cancel(ray_start_regular, use_force):
|
||||
signaler = SignalActor.remote()
|
||||
|
||||
@ray.remote
|
||||
def wait_for(y):
|
||||
return ray.get(y[0])
|
||||
|
||||
@ray.remote
|
||||
def remote_wait(sg):
|
||||
return [wait_for.remote([sg[0]])]
|
||||
|
||||
sig = signaler.wait.remote()
|
||||
|
||||
outer = remote_wait.remote([sig])
|
||||
inner = ray.get(outer)[0]
|
||||
|
||||
with pytest.raises(RayTimeoutError):
|
||||
ray.get(inner, 1)
|
||||
|
||||
ray.cancel(inner)
|
||||
|
||||
with pytest.raises(valid_exceptions(use_force)):
|
||||
ray.get(inner, 10)
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
sys.exit(pytest.main(["-v", __file__]))
|
||||
|
||||
@@ -1679,7 +1679,7 @@ def kill(actor):
|
||||
|
||||
|
||||
def cancel(object_id, force=False):
|
||||
"""Cancels a locally-submitted task according to the following conditions.
|
||||
"""Cancels a task according to the following conditions.
|
||||
|
||||
If the specified task is pending execution, it will not be executed. If
|
||||
the task is currently executing, the behavior depends on the ``force``
|
||||
@@ -1698,8 +1698,7 @@ def cancel(object_id, force=False):
|
||||
force (boolean): Whether to force-kill a running task by killing
|
||||
the worker that is running the task.
|
||||
Raises:
|
||||
ValueError: This is also raised for actor tasks, already completed
|
||||
tasks, and non-locally submitted tasks.
|
||||
TypeError: This is also raised for actor tasks.
|
||||
"""
|
||||
worker = ray.worker.global_worker
|
||||
worker.check_connected()
|
||||
|
||||
Reference in New Issue
Block a user