Cythonize 射线演员 class

Cythonize ray actor class

我正在使用 Ray 库,然后我想对我的包进行 Cythonize。 while there is a reference 如何适配正则远程函数

some_cython_func = ray.remote(some_cython_module.some_cython_func)

不清楚如何处理Ray Actor(class级别的装饰器)

@ray.remote
class MyService:
    def __init__(self):
        pass
    def run(self):
        ...
    def helper(self):
        ...

此代码在被 cythonized 后产生这样的错误

  File "/Users/user/anaconda3/envs/ray-test/lib/python3.7/site-packages/ray/actor.py", line 538, in _remote
    meta.method_meta.methods.keys())
  File "/Users/user/anaconda3/envs/ray-test/lib/python3.7/site-packages/ray/function_manager.py", line 358, in export_actor_class
    "class": pickle.dumps(Class),
  File "/Users/user/anaconda3/envs/ray-test/lib/python3.7/site-packages/ray/cloudpickle/cloudpickle_fast.py", line 70, in dumps
    cp.dump(obj)
  File "/Users/user/anaconda3/envs/ray-test/lib/python3.7/site-packages/ray/cloudpickle/cloudpickle_fast.py", line 656, in dump
    return Pickler.dump(self, obj)
_pickle.PicklingError: Can't pickle <cyfunction MyService.__init__ at 0x7fc230367c80>: it's not the same object as app.my_service.__init__

如何rewrite/adapt现有的工作光线代码与 Cython 一起工作?

Python 3.7.9 / ray==0.8.6

是的,这似乎是一个简单的解决方案,因为

MyService = ray.remote(_MyService)

工作没有问题。

Ref to the Ray source code