简介
以如下的示例为例。
import ray
ray.init(num_cpus=4)
@ray.remote
def hello():
return "Hello World!!!"
oid = hello.remote()
print(ray.get(oid))
上述的 @ray.remote
实际上是一个装饰器,详细可以参考 Python 闭包和装饰器 中的介绍。
remote()
|-make_remote()
|-RemoteFunction()
|-actor._make_actor()
ray.init()
CoreWorker::SubmitTask()
CoreWorker::submit_actor_task()
对象存储
通过 remote()
调用返回的是 ObjectRef
对象,其序列化和反序列化实现可以参考 Serialization 中的介绍。