I am developing Actor
class and ray.wait()
to collect the results.
Below is the code and console outputs which is collecting the result for only 2 Actors when there are 3 Actors.
import time
import ray
@ray.remote
class Tester:
def __init__(self, param):
self.param = param
def run(self):
return self.param
params = [0,1,2]
testers = []
for p in params:
tester = Tester.remote(p)
testers.append(tester)
runs = []
for i, tester in enumerate(testers):
runs.append(tester.run.remote())
while len(runs):
done_id, result_ids = ray.wait(runs)
#runs size is not decreasing
result = ray.get(done_id[0])
print('result:{}'.format(result))
time.sleep(1)
result:2
(pid=819202)
(pid=819200)
(pid=819198)
result:1
result:0
result:0
result:0
result:0
result:0
...
...
...
The console is printing out forever because the runs variable's size is not reduced.
When I call ray.wait(runs)
and get the done_id
, runs's element with the done_id
should be removed, but it is not removed.
I want the console output to be like below.
result:2
(pid=819202)
(pid=819200)
(pid=819198)
result:1
result:0