Skip to content

Commit

Permalink
Print correctly actor class name in exception
Browse files Browse the repository at this point in the history
Signed-off-by: Constantin M Adam <cmadam@us.ibm.com>
  • Loading branch information
cmadam committed Nov 22, 2024
1 parent d559a2e commit 25b3a7b
Showing 1 changed file with 12 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -15,12 +15,13 @@
from typing import Any

import ray
from ray.experimental.state.api import list_actors
from data_processing.utils import GB, UnrecoverableException, get_logger
from ray.actor import ActorHandle
from ray.exceptions import RayError
from ray.experimental.state.api import list_actors
from ray.util.actor_pool import ActorPool


MAX_LIST = 10000 # Max number of actors returned by list


Expand Down Expand Up @@ -112,7 +113,7 @@ def operator() -> ActorHandle:
return clazz.options(**actor_options).remote(params)

logger = get_logger(__name__)
cls_name = clazz.__class__.__name__.replace('ActorClass(', '').replace(')','')
cls_name = clazz.__class__.__name__.replace("ActorClass(", "").replace(")", "")
current = list_actors(filters=[("class_name", "=", cls_name), ("state", "=", "ALIVE")], limit=MAX_LIST)
c_len = len(current)
actors = [operator() for _ in range(n_actors)]
Expand All @@ -126,20 +127,23 @@ def operator() -> ActorHandle:
if len(alive) >= n_actors + c_len:
return actors
# failed
if len(alive) >= n_actors/2 + c_len:
if len(alive) >= n_actors / 2 + c_len:
# At least half of the actors were created
logger.info(f"created {n_actors}, alive {len(alive)} Running with less actors")
created_ids = [item.actor_id for item in alive if item not in current]
return [
actor for actor in actors
if (str(actor._ray_actor_id).
replace('ActorID(', '').replace(')','') in created_ids)]
actor
for actor in actors
if (str(actor._ray_actor_id).replace("ActorID(", "").replace(")", "") in created_ids)
]
else:
# too few actors created
raise UnrecoverableException(f"Created {n_actors}, alive {len(alive)}. Too few actors were created")
else:
raise UnrecoverableException(f"Overall number of actors of class {clazz.__name__} is {overall}. "
f"Too many actors to create, greater then {MAX_LIST}")
raise UnrecoverableException(
f"Overall number of actors of class {cls_name} is {overall}. "
f"Too many actors to create, greater then {MAX_LIST}"
)

@staticmethod
def process_files(
Expand Down

0 comments on commit 25b3a7b

Please sign in to comment.