繁体   English   中英

Cythonize 射线演员 class

[英]Cythonize ray actor class

我正在使用 Ray 库,然后我想 Cythonize 我的 package。 虽然有如何适配常规远程 function 的参考

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__

如何重写/调整现有的工作射线代码以使用 Cython?

Python 3.7.9 / ray==0.8.6

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

MyService = ray.remote(_MyService)

工作没有问题。

参考雷源代码

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM