PolarBear10
PolarBear10

Reputation: 2305

Ray python example with multiple returns and calling ray.get()

The below code does the desired behaviour. Is it possible to pass the second argument from the first two functions without having to call ray.get prematurely ?

@ray.remote
def color():
    image=cv2.imread("frame30.png", flags=0)
    argument= "Hello"
    return image,argument

@ray.remote
def black():
    image=cv2.imread("frame30.png", flags=0)
    argument= "world"
    return image,argument

@ray.remote
def concate_two_args(a,b):
    return a + " " + b

col= color.remote()
blk= black.remote()

#Do I have to "ray.get" in order to pass the results to concate_two_args?
temp1= ray.get(col)[1]
temp2= ray.get(blk)[1]

results= concate_two_args.remote(temp1,temp2)

ray.get(results)

Doing this directly

col, string= color.remote()

ray.get(string)

returns

TypeError: cannot unpack non-iterable ray._raylet.ObjectRef object

Upvotes: 3

Views: 3473

Answers (1)

Sang
Sang

Reputation: 925

Can you try adding num_returns to @ray.remote? For example,

@ray.remote(num_returns=2)
def color():
    image=cv2.imread("frame30.png", flags=0)
    argument= "Hello"
    return image,argument

@ray.remote(num_returns=2)
def black():
    image=cv2.imread("frame30.png", flags=0)
    argument= "world"
    return image,argument

Upvotes: 5

Related Questions