python - 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'
上那条线。
请问我这个代码哪里出错了?
解决方案
您正在访问未定义remote()
的函数。do_work
你的意思是打电话do_work()
吗?
推荐阅读
- r - 将数据框和数据框列表组合成一维数据框列表,R
- latex - 在将乳胶输入 Wolfram 时,我能否像在 Symbolab 中一样查看实时变化的方程?
- python - 如何使用python链接word文档中的内容控制框
- firebase-cloud-messaging - 我可以使用 fcm 在 web 中推送资产版本吗
- firebase - Azure devops 将 iOS 应用程序部署到 Firebase 应用程序分发
- java - 在 Java 中创建表后创建 DynamoDB 全局二级索引
- javascript - 出现错误:Route.get() 需要一个回调函数,但在 authMiddleware 中添加新函数时得到了一个 [object Object]
- amazon-web-services - AWS CloudWatch 日志见解
- flutter - 颤振:如何在登录表单中自动填写密码
- amazon-web-services - 爬虫未创建架构