Make ActorHandles pickleable, also make proper ActorHandle and ActorC… (#2007)

* Make ActorHandles pickleable, also make proper ActorHandle and ActorClass classes.

* Fix bug.

* Fix actor test bug.

* Update __ray_terminate__ usage.

* Fix most linting, add documentation, and small cleanups.

* Handle forking and pickling differently for actor handles. Fix linting.

* Fixes for named actors via pickling.

* Generate actor handle IDs deterministically in the pickling case.
This commit is contained in:
Robert Nishihara
2018-05-08 19:19:07 -07:00
committed by Philipp Moritz
parent 2048b546ff
commit 77c8aa7627
10 changed files with 561 additions and 381 deletions
+30 -9
View File
@@ -1822,7 +1822,12 @@ class DistributedActorHandles(unittest.TestCase):
@ray.remote
class Counter(object):
pass
def __init__(self):
self.x = 0
def inc(self):
self.x += 1
return self.x
@ray.remote
def f():
@@ -1832,18 +1837,34 @@ class DistributedActorHandles(unittest.TestCase):
def g():
return [Counter.remote()]
with self.assertRaises(Exception):
ray.put(Counter.remote())
# Currently, calling ray.put on an actor handle is allowed, but is
# there a good use case?
counter = Counter.remote()
counter_id = ray.put(counter)
new_counter = ray.get(counter_id)
assert ray.get(new_counter.inc.remote()) == 1
assert ray.get(counter.inc.remote()) == 2
assert ray.get(new_counter.inc.remote()) == 3
with self.assertRaises(Exception):
ray.get(f.remote())
# The below test is commented out because it currently does not behave
# properly. The call to g.remote() does not raise an exception because
# even though the actor handle cannot be pickled, pyarrow attempts to
# serialize it as a dictionary of its fields which kind of works.
# self.assertRaises(Exception):
# ray.get(g.remote())
# The below test works, but do we want to disallow this usage?
ray.get(g.remote())
def testPicklingActorHandle(self):
ray.worker.init(num_workers=1)
@ray.remote
class Foo(object):
def method(self):
pass
f = Foo.remote()
new_f = ray.worker.pickle.loads(ray.worker.pickle.dumps(f))
# Verify that we can call a method on the unpickled handle. TODO(rkn):
# we should also test this from a different driver.
ray.get(new_f.method.remote())
class ActorPlacementAndResources(unittest.TestCase):