Cythonize 射线演员类

问题描述

我正在使用 Ray 库,然后我想对我的包进行 Cythonize。 而there is a reference如何适配常规远程功能

qtquick2plugin.dll

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

some_cython_func = ray.remote(some_cython_module.some_cython_func)

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

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

如何重写/改编现有的工作光线代码以与 Cython 一起工作?

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__ / Python 3.7.9

解决方法

是的,看起来像一个简单的解决方案

MyService = ray.remote(_MyService)

工作没有问题。

Ref to the Ray source code