Implement Detached Actor (#6036)

* Arg propagation works

* Implement persistent actor

* Add doc

* Initialize is_persistent_

* Rename persistent->detached

* Address comment

* Make test passes

* Address comment

* Python2 compatiblity

* Fix naming, py2

* Lint
This commit is contained in:
Simon Mo
2019-11-01 10:28:23 -07:00
committed by GitHub
parent f7455839bf
commit 7f5b3502da
16 changed files with 164 additions and 27 deletions
+40
View File
@@ -235,3 +235,43 @@ To get information about the current available resource capacity of your cluster
.. autofunction:: ray.available_resources
:noindex:
Detached Actors
-----------------------------------
When original actor handles goes out of scope or the driver that originally
created the actor exits, ray will clean up the actor by default. If you want
to make sure the actor is kept alive, you can use
``_remote(name="some_name", detached=True)`` to keep the actor alive after
the driver exits. The actor will have a globally unique name and can be
accessed across different drivers.
For example, you can instantiate and register a persistent actor as follows:
.. code-block:: python
counter = Counter._remote(name="CounterActor", detached=True)
The CounterActor will be kept alive even after the driver running above script
exits. Therefore it is possible to run the following script in a different
driver:
.. code-block:: python
counter = ray.experimental.get_actor("CounterActor")
print(ray.get(counter.get_counter.remote()))
Note that just creating a named actor is allowed, this actor will be cleaned
up after driver exits:
.. code-block:: python
Counter._remote(name="CounterActor")
However, creating a detached actor without name is not allowed because there
will be no way to retrieve the actor handle and the resource is leaked.
.. code-block:: python
# Can't do this!
Counter._remote(detached=True)