Skip to content

Commit

Permalink
feat: boolean function to check if world is broken
Browse files Browse the repository at this point in the history
A broken world exception is raised for collective operations such as
send and recv. However, if those operations are not called and
runtime error is not raised, the broken world won't be noticed until
any of the operations is called. To check if the world is broken or not
without calling the operations, a new function is introduced.
  • Loading branch information
myungjin committed Aug 5, 2024
1 parent dd6e3b5 commit 452474f
Showing 1 changed file with 16 additions and 2 deletions.
18 changes: 16 additions & 2 deletions multiworld/world_communicator.py
Original file line number Diff line number Diff line change
Expand Up @@ -76,18 +76,32 @@ def __del__(self):
"""Cleanup the class instance."""
del self._broken_world

def add_world(self, world_name):
def add_world(self, world_name) -> None:
"""Add a new world to the world comm manager."""
self._broken_world[world_name] = False

def remove_world(self, world_name):
def remove_world(self, world_name) -> None:
"""Remove a world from the world comm manager."""
logger.debug(f"remove world {world_name}")
try:
self._broken_world[world_name] = True
except KeyError:
pass

def is_broken(self, world_name: str) -> bool:
"""Return true if the given world is broken; otherwise return false.
A world is considered broken if no key for the world name is found.
Args:
world_name: name of world
Returns:
A boolean value to indicate whether a world is broken or not.
"""
logger.debug(f"check if world {world_name} is broken")
return self._broken_world.get(world_name, True)

async def _wait_work(self, work: Work, world_name: str) -> None:
"""Do busy-waiting for work to be done.
Expand Down

0 comments on commit 452474f

Please sign in to comment.