首页 > 解决方案 > python ray AttributeError:'function'没有属性'remote'

问题描述

我正在尝试根据环境变量是否为真在现有代码上使用 ray 模块。这是我到目前为止所做的。此代码结构与我的相似,但不完全是由于它的大小。

import os

if os.getenv("PARALLEL"):
    import ray
    ray.init()

class A(object):
    def __init__(self, attr):
          self.attr = attr 

    def may_be_remote(func):
          return ray.remote(func) if os.getenv("PARALLEL") else func

    @may_be_remote
    def do_work(self):
          #work code

    def execute(self, n):
           for _ in range(n):
                do_work.remote()

然后,我调用 A 类的执行函数:

a = A()
a.execute(7)

AttributeError : 'function' has no attribute 'remote'上那条线。

请问我这个代码哪里出错了?

标签: pythonray

解决方案


您正在访问未定义remote()的函数。do_work

你的意思是打电话do_work()吗?


推荐阅读