How can I synchronously create an actor?

When creating an actor if the actor’s __init__ method throws an exception that exception doesn’t seem to be propagated back during creation.

Concretely how can I make this:

@ray.remote
class FailingActor:
    def __init__(self):
        raise Exception("dead")

FailingActor.remote() # <- I want to see an exception thrown here

throw an exception during FailngActor.remote()?

If I can’t do that is it best practice to move any initialization that can fail into another method so I can do ray.get(actor.setup.remote()) shaped pattern?

All .remote() calls are meant to be asynchronous, so that’s why you never see the exception thrown during the actor creation call. Actor creation calls also return an actor handle, not a future, so you can’t do ray.get() on them to block either.

The exception should get thrown if you try another task on the actor, though. That can also be useful if you want to wait until the actor is initialized before doing anything else, like this:

@ray.remote
class FailingActor:
    def __init__(self):
        raise Exception("dead")
    def ready(self):
        return

h = FailingActor.remote()
ray.get(h.ready.remote())  # <- Exception thrown here.
1 Like

That definitely helps clear up my confusion between Tasks/Actor method calls & Actor init!

Having an empty ready() method seems like a great way of handling this.

Thanks! :smiley: