mirror of
https://github.com/wassname/ray.git
synced 2026-06-28 09:12:56 +08:00
Cross language exception (#10023)
This commit is contained in:
+17
-16
@@ -9,6 +9,7 @@ import ray.utils
|
||||
from ray.utils import _random_string
|
||||
from ray.gcs_utils import ErrorType
|
||||
from ray.exceptions import (
|
||||
RayError,
|
||||
PlasmaObjectNotAvailable,
|
||||
RayTaskError,
|
||||
RayActorError,
|
||||
@@ -221,10 +222,10 @@ class SerializationContext:
|
||||
def _deserialize_msgpack_data(self, data, metadata):
|
||||
msgpack_data, pickle5_data = split_buffer(data)
|
||||
|
||||
if metadata == ray_constants.OBJECT_METADATA_TYPE_CROSS_LANGUAGE:
|
||||
python_objects = []
|
||||
else:
|
||||
if metadata == ray_constants.OBJECT_METADATA_TYPE_PYTHON:
|
||||
python_objects = self._deserialize_pickle5_data(pickle5_data)
|
||||
else:
|
||||
python_objects = []
|
||||
|
||||
try:
|
||||
|
||||
@@ -262,8 +263,7 @@ class SerializationContext:
|
||||
# independent.
|
||||
if error_type == ErrorType.Value("TASK_EXECUTION_EXCEPTION"):
|
||||
obj = self._deserialize_msgpack_data(data, metadata)
|
||||
assert isinstance(obj, RayTaskError)
|
||||
return obj
|
||||
return RayError.from_bytes(obj)
|
||||
elif error_type == ErrorType.Value("WORKER_DIED"):
|
||||
return RayWorkerError()
|
||||
elif error_type == ErrorType.Value("ACTOR_DIED"):
|
||||
@@ -347,7 +347,16 @@ class SerializationContext:
|
||||
metadata, inband, writer,
|
||||
self.get_and_clear_contained_object_refs())
|
||||
|
||||
def _serialize_to_msgpack(self, metadata, value):
|
||||
def _serialize_to_msgpack(self, value):
|
||||
# Only RayTaskError is possible to be serialized here. We don't
|
||||
# need to deal with other exception types here.
|
||||
if isinstance(value, RayTaskError):
|
||||
metadata = str(
|
||||
ErrorType.Value("TASK_EXECUTION_EXCEPTION")).encode("ascii")
|
||||
value = value.to_bytes()
|
||||
else:
|
||||
metadata = ray_constants.OBJECT_METADATA_TYPE_CROSS_LANGUAGE
|
||||
|
||||
python_objects = []
|
||||
|
||||
def _python_serializer(o):
|
||||
@@ -358,10 +367,10 @@ class SerializationContext:
|
||||
msgpack_data = MessagePackSerializer.dumps(value, _python_serializer)
|
||||
|
||||
if python_objects:
|
||||
metadata = ray_constants.OBJECT_METADATA_TYPE_PYTHON
|
||||
pickle5_serialized_object = \
|
||||
self._serialize_to_pickle5(metadata, python_objects)
|
||||
else:
|
||||
metadata = ray_constants.OBJECT_METADATA_TYPE_CROSS_LANGUAGE
|
||||
pickle5_serialized_object = None
|
||||
|
||||
return MessagePackSerializedObject(metadata, msgpack_data,
|
||||
@@ -379,15 +388,7 @@ class SerializationContext:
|
||||
# that this object can also be read by Java.
|
||||
return RawSerializedObject(value)
|
||||
else:
|
||||
# Only RayTaskError is possible to be serialized here. We don't
|
||||
# need to deal with other exception types here.
|
||||
if isinstance(value, RayTaskError):
|
||||
metadata = str(ErrorType.Value(
|
||||
"TASK_EXECUTION_EXCEPTION")).encode("ascii")
|
||||
else:
|
||||
metadata = ray_constants.OBJECT_METADATA_TYPE_PYTHON
|
||||
|
||||
return self._serialize_to_msgpack(metadata, value)
|
||||
return self._serialize_to_msgpack(value)
|
||||
|
||||
def register_custom_serializer(self,
|
||||
cls,
|
||||
|
||||
Reference in New Issue
Block a user