mirror of
https://github.com/vale981/ray
synced 2025-03-05 18:11:42 -05:00
[Core] Force get_actor(name)'s name to be non-empty string (#12218)
This commit is contained in:
parent
32d159a2ed
commit
7f1f16d99e
3 changed files with 11 additions and 0 deletions
|
@ -216,6 +216,9 @@ public final class RayNativeRuntime extends AbstractRayRuntime {
|
||||||
@SuppressWarnings("unchecked")
|
@SuppressWarnings("unchecked")
|
||||||
@Override
|
@Override
|
||||||
public <T extends BaseActorHandle> Optional<T> getActor(String name, boolean global) {
|
public <T extends BaseActorHandle> Optional<T> getActor(String name, boolean global) {
|
||||||
|
if (name.isEmpty()) {
|
||||||
|
return Optional.empty();
|
||||||
|
}
|
||||||
byte[] actorIdBytes = nativeGetActorIdOfNamedActor(name, global);
|
byte[] actorIdBytes = nativeGetActorIdOfNamedActor(name, global);
|
||||||
ActorId actorId = ActorId.fromBytes(actorIdBytes);
|
ActorId actorId = ActorId.fromBytes(actorIdBytes);
|
||||||
if (actorId.isNil()) {
|
if (actorId.isNil()) {
|
||||||
|
|
|
@ -1032,6 +1032,12 @@ def test_kill(ray_start_regular_shared):
|
||||||
ray.kill("not_an_actor_handle")
|
ray.kill("not_an_actor_handle")
|
||||||
|
|
||||||
|
|
||||||
|
def test_get_actor_no_input(ray_start_regular_shared):
|
||||||
|
for bad_name in [None, "", " "]:
|
||||||
|
with pytest.raises(ValueError):
|
||||||
|
ray.get_actor(bad_name)
|
||||||
|
|
||||||
|
|
||||||
if __name__ == "__main__":
|
if __name__ == "__main__":
|
||||||
import pytest
|
import pytest
|
||||||
sys.exit(pytest.main(["-v", __file__]))
|
sys.exit(pytest.main(["-v", __file__]))
|
||||||
|
|
|
@ -1538,6 +1538,8 @@ def get_actor(name):
|
||||||
Raises:
|
Raises:
|
||||||
ValueError if the named actor does not exist.
|
ValueError if the named actor does not exist.
|
||||||
"""
|
"""
|
||||||
|
if not name:
|
||||||
|
raise ValueError("Please supply a non-empty value to get_actor")
|
||||||
worker = global_worker
|
worker = global_worker
|
||||||
worker.check_connected()
|
worker.check_connected()
|
||||||
handle = worker.core_worker.get_named_actor_handle(name)
|
handle = worker.core_worker.get_named_actor_handle(name)
|
||||||
|
|
Loading…
Add table
Reference in a new issue