Fix support for actor classmethods (#2146)

This commit is contained in:
Eric Liang
2018-05-28 17:43:23 -07:00
committed by Robert Nishihara
parent eb1d7ac4bc
commit bc2a83e698
2 changed files with 37 additions and 2 deletions
+11 -2
View File
@@ -17,6 +17,12 @@ from ray.utils import _random_string, is_cython, push_error_to_driver
DEFAULT_ACTOR_METHOD_NUM_RETURN_VALS = 1
def is_classmethod(f):
"""Returns whether the given method is a classmethod."""
return hasattr(f, "__self__") and f.__self__ is not None
def compute_actor_handle_id(actor_handle_id, num_forks):
"""Deterministically compute an actor handle ID.
@@ -242,7 +248,10 @@ def make_actor_method_executor(worker, method_name, method, actor_imported):
# Execute the assigned method and save a checkpoint if necessary.
try:
method_returns = method(actor, *args)
if is_classmethod(method):
method_returns = method(*args)
else:
method_returns = method(actor, *args)
except Exception:
# Save the checkpoint before allowing the method exception to be
# thrown.
@@ -500,7 +509,7 @@ class ActorClass(object):
# don't support, there may not be much the user can do about it.
signature.check_signature_supported(method, warn=True)
self._method_signatures[method_name] = signature.extract_signature(
method, ignore_first=True)
method, ignore_first=not is_classmethod(method))
# Set the default number of return values for this method.
if hasattr(method, "__ray_num_return_vals__"):