mirror of
https://github.com/wassname/ray.git
synced 2026-07-09 04:00:44 +08:00
Enable actor methods to be decorated on the caller side also and get postprocessors. (#4732)
* Allow decorating ray actor methods. * Add test. * Add get postprocessors. * Improve documentation. * Make it work for remote functions. * Temporary fix.
This commit is contained in:
committed by
Philipp Moritz
parent
897b35ce36
commit
d81e71e297
+26
-14
@@ -156,6 +156,9 @@ class Worker(object):
|
||||
# increment every time when `ray.shutdown` is called.
|
||||
self._session_index = 0
|
||||
self._current_task = None
|
||||
# Functions to run to process the values returned by ray.get. Each
|
||||
# postprocessor must take two arguments ("object_ids", and "values").
|
||||
self._post_get_hooks = []
|
||||
|
||||
@property
|
||||
def connected(self):
|
||||
@@ -1455,7 +1458,7 @@ def init(redis_address=None,
|
||||
return _global_node.address_info
|
||||
|
||||
|
||||
# Functions to run as callback after a successful ray init
|
||||
# Functions to run as callback after a successful ray init.
|
||||
_post_init_hooks = []
|
||||
|
||||
|
||||
@@ -1493,7 +1496,10 @@ def shutdown(exiting_interpreter=False):
|
||||
_global_node.kill_all_processes(check_alive=False, allow_graceful=True)
|
||||
_global_node = None
|
||||
|
||||
# TODO(rkn): Instead of manually reseting some of the worker fields, we
|
||||
# should simply set "global_worker" to equal "None" or something like that.
|
||||
global_worker.set_mode(None)
|
||||
global_worker._post_get_hooks = []
|
||||
|
||||
|
||||
atexit.register(shutdown, True)
|
||||
@@ -2175,23 +2181,29 @@ def get(object_ids):
|
||||
# In LOCAL_MODE, ray.get is the identity operation (the input will
|
||||
# actually be a value not an objectid).
|
||||
return object_ids
|
||||
|
||||
is_individual_id = isinstance(object_ids, ray.ObjectID)
|
||||
if is_individual_id:
|
||||
object_ids = [object_ids]
|
||||
|
||||
if not isinstance(object_ids, list):
|
||||
raise ValueError("'object_ids' must either by an object ID "
|
||||
"or a list of object IDs.")
|
||||
|
||||
global last_task_error_raise_time
|
||||
if isinstance(object_ids, list):
|
||||
values = worker.get_object(object_ids)
|
||||
for i, value in enumerate(values):
|
||||
if isinstance(value, RayError):
|
||||
last_task_error_raise_time = time.time()
|
||||
raise value
|
||||
return values
|
||||
else:
|
||||
value = worker.get_object([object_ids])[0]
|
||||
values = worker.get_object(object_ids)
|
||||
for i, value in enumerate(values):
|
||||
if isinstance(value, RayError):
|
||||
# If the result is a RayError, then the task that created
|
||||
# this object failed, and we should propagate the error message
|
||||
# here.
|
||||
last_task_error_raise_time = time.time()
|
||||
raise value
|
||||
return value
|
||||
|
||||
# Run post processors.
|
||||
for post_processor in worker._post_get_hooks:
|
||||
values = post_processor(object_ids, values)
|
||||
|
||||
if is_individual_id:
|
||||
values = values[0]
|
||||
return values
|
||||
|
||||
|
||||
def put(value):
|
||||
|
||||
Reference in New Issue
Block a user