disabled-commands
参数需移除 keys 以允许执行 keys 命令。detached_actor.py
import ray @ray.remote(num_cpus=1) class Counter: def __init__(self): self.value = 0 def increment(self): self.value += 1 return self.value ray.init(namespace="default_namespace") Counter.options(name="counter_actor", lifetime="detached").remote()
increment_counter.py
import ray ray.init(namespace="default_namespace") counter = ray.get_actor("counter_actor") print(ray.get(counter.increment.remote()))
python3 detached_actor.py 2025-01-21 21:48:55,351 INFO worker.py:1461 -- Using address 127.0.0.1:6379 set in the environment variable RAY_ADDRESS 2025-01-21 21:48:55,351 INFO worker.py:1601 -- Connecting to existing Ray cluster at address: 10.1.0.134:6379... 2025-01-21 21:48:55,357 INFO worker.py:1777 -- Connected to Ray cluster. View the dashboard at http://10.1.0.134:8265 python3 increment_counter.py 2025-01-21 21:49:18,140 INFO worker.py:1461 -- Using address 127.0.0.1:6379 set in the environment variable RAY_ADDRESS 2025-01-21 21:49:18,141 INFO worker.py:1601 -- Connecting to existing Ray cluster at address: 10.1.0.134:6379... 2025-01-21 21:49:18,146 INFO worker.py:1777 -- Connected to Ray cluster. View the dashboard at http://10.1.0.134:8265 1
ps aux | grep gcs_server | grep -v grep | awk '{print $2}' | xargs kill -9
返回值为2,符合预期。
python3 increment_counter.py 2025-01-21 21:53:12,456 INFO worker.py:1461 -- Using address 127.0.0.1:6379 set in the environment variable RAY_ADDRESS 2025-01-21 21:53:12,456 INFO worker.py:1601 -- Connecting to existing Ray cluster at address: 10.1.0.134:6379... 2025-01-21 21:53:12,462 INFO worker.py:1777 -- Connected to Ray cluster. View the dashboard at http://10.1.0.134:8265 2