如果我理解正确,下面的代码应该在并行中运行
@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在单个进程中运行。因此,worker.train.remote((将是同步的。