[Core] How to make sure an actor is initialized?

Is there a way to make sure that an actor is fully initialized? For an example, I have some

@ray.remote    
class Worker ():
    def __init__(self, mnp_id, main_arrays):
        #doing some prep work    

Now, I wanna fire up a number of workers. I do it like this:

Ws = [Worker.remote (mnp, main_arrays) for _ in range(CPU-OVERHEAD)]

What I would love to know is how to make sure that has finished its prep work? Something like:

ray.get (Ws)

But that fails with:

TypeError: Attempting to call `get` on the value Actor(Worker,9624f296d48a0a1967232fbf01000000), which is not an ray.ObjectRef.

What I do now is:

Ws = [Worker.remote (mnp, main_arrays) for _ in range(CPU-OVERHEAD)]
time.sleep (2)

But this is just embarrassing. How do I do an ray.get() on __init__?

There is a straightforward work-around. Basically, leave __init__ empty and do all heavy-lifting prep work in a separate method on which you can call ray.get (). But I was just wondering …

Right now, the best way is to create a mock method and call it.

@ray.remote
class A:
    def ready():
        pass

a = A.remote()
ray.get(a.ready.remote())

There’s also an open feature request to support this natively; Feature request on `actor.wait(timeout_ms)` API · Issue #14923 · ray-project/ray · GitHub

1 Like

Is there any change now (2023)?
In my use case, I need to wrapper some customer’s code which I can’t controll, they might do heavy work in init

I think from ray 2.3, you have

actor.__ray_ready__.remote()

Not sure if it is public. cc @kai ?

We don’t publicly document it, but you should be able to use this going forward.