Skip to content

Commit

Permalink
[autoscaler] Make NodeLaunchException serializable (ray-project#31256)
Browse files Browse the repository at this point in the history
In order to make node launch exceptions serializable, drop the optional stack trace which isn't serializable.

Co-authored-by: Alex <[email protected]>
Signed-off-by: tmynn <[email protected]>
  • Loading branch information
2 people authored and tamohannes committed Jan 25, 2023
1 parent a6153fb commit d6c7a06
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 1 deletion.
8 changes: 8 additions & 0 deletions python/ray/autoscaler/node_launch_exception.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,3 +27,11 @@ def __init__(
self.category = category
self.description = description
self.src_exc_info = src_exc_info

def __reduce__(self):
# NOTE: Since tracebacks can't be pickled, we'll drop the optional
# traceback if we have to serialize this object.
return (
self.__class__,
(self.category, self.description, None),
)
22 changes: 21 additions & 1 deletion python/ray/tests/test_autoscaler_e2e.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,13 @@
from ray.autoscaler._private.constants import AUTOSCALER_METRIC_PORT

import ray
import sys
from ray._private.test_utils import (
wait_for_condition,
get_metric_check_condition,
)
from ray.cluster_utils import AutoscalingCluster
from ray.autoscaler.node_launch_exception import NodeLaunchException


def test_ray_status_e2e(shutdown_only):
Expand Down Expand Up @@ -111,8 +113,26 @@ def ping(self):
cluster.shutdown()


def test_node_launch_exception_serialization(shutdown_only):
ray.init(num_cpus=1)

exc_info = None
try:
raise Exception("Test exception.")
except Exception:
exc_info = sys.exc_info()
assert exc_info is not None

exc = NodeLaunchException("cat", "desc", exc_info)

after_serialization = ray.get(ray.put(exc))

assert after_serialization.category == exc.category
assert after_serialization.description == exc.description
assert after_serialization.src_exc_info is None


if __name__ == "__main__":
import sys
import os
import pytest

Expand Down

0 comments on commit d6c7a06

Please sign in to comment.