python-3.x - 无法理解 ray 中的并行代码输出
问题描述
如果我理解正确,以下代码应该并行运行
@ray.remote
class Worker:
...
def train(self, item, i):
time.sleep(i)
logging.info(f'{i} {item}')
...
worker = Worker.remote()
list = ['a', 'b', 'c']
results = ray.get([worker.train.remote(item, len(list) - idx) for idx, item in enumerate(list)])
print(results)
logging.info("successful print")
这应该输出
1 c
2 b
3 a
[1,2,3]
但是,这会输出:
3 a
2 b
[3,2,1]
我是使用 ray 的新手,无法理解这种行为。如果有人能指出我正确的方向,那就太好了!
解决方案
Actor is running within a single process. As a result, worker.train.remote() will be synchronous.
推荐阅读
- sqlite - 我可以在同一语句中多次使用 better-sqlite.get() 或 better-sqlite.all() 中的单个参数吗
- python - 当提供一个 pandas Series 对象作为另一个 pandas Series 对象的索引时会发生什么?
- python-3.x - 如何根据相似的列名对 DataFrame 进行子集化
- angular - 子控件在父控件之前呈现
- javascript - 当我从 PostMan 发送图像文件时,NodeJS multer 出现错误(req.file 未定义)
- r - 将名称和时间拆分为新行
- python - Pygame 零 Flappy Bird 修改
- windows - 注册子键自动打开dwg文件
- laravel - GlobalVueStyles:不适用于 vue 组件中的全局 Sass
- php - 无法使用 PHP PDO 和 Docker 连接到 Postgres 数据库