Fix actor garbage collection by breaking cyclic references (#1064)

* Fix bug in wait_for_pid_to_exit, add test for actor deletion.

* Fix actor garbage collection by breaking cyclic references

* Add test for calling actor method immediately after actor creation.

* Fix bug, must dispatch tasks when workers are killed.

* Fix python test

* Fix cyclic reference problem by creating ActorMethod objects on the fly.

* Try simply increasing the time allowed for many_drivers_test.py.
This commit is contained in:
Stephanie Wang
2017-10-05 00:55:33 -07:00
committed by Robert Nishihara
parent 971becc905
commit aebe9f9374
5 changed files with 66 additions and 22 deletions
+36
View File
@@ -5,10 +5,12 @@ from __future__ import print_function
import collections
import random
import numpy as np
import os
import time
import unittest
import ray
import ray.test.test_utils
class ActorAPI(unittest.TestCase):
@@ -279,6 +281,40 @@ class ActorMethods(unittest.TestCase):
ray.worker.cleanup()
def testActorDeletion(self):
ray.init(num_workers=0)
# Make sure that when an actor handles goes out of scope, the actor
# destructor is called.
@ray.remote
class Actor(object):
def getpid(self):
return os.getpid()
a = Actor.remote()
pid = ray.get(a.getpid.remote())
a = None
ray.test.test_utils.wait_for_pid_to_exit(pid)
actors = [Actor.remote() for _ in range(10)]
pids = ray.get([a.getpid.remote() for a in actors])
a = None
actors = None
[ray.test.test_utils.wait_for_pid_to_exit(pid) for pid in pids]
@ray.remote
class Actor(object):
def method(self):
return 1
# Make sure that if we create an actor and call a method on it
# immediately, the actor doesn't get killed before the method is
# called.
self.assertEqual(ray.get(Actor.remote().method.remote()), 1)
ray.worker.cleanup()
def testActorState(self):
ray.init()