diff --git a/scripts/spartan/worker.py b/scripts/spartan/worker.py index b4ebbd8..6f505fc 100644 --- a/scripts/spartan/worker.py +++ b/scripts/spartan/worker.py @@ -707,11 +707,19 @@ class Worker: logger.error(f"{err_msg}: {response}") return False - def set_state(self, state: State): + def set_state(self, state: State, expect_cycle: bool = False): + """ + Updates the state of a worker if considered a valid operation + + Args: + state: the new state to try transitioning to + expect_cycle: whether this transition might be a no-op/self-loop + + """ state_cache = self.state def transition(ns: State): - if ns == self.state: + if ns == self.state and expect_cycle is False: logger.debug(f"{self.label}: potentially redundant transition {self.state.name} -> {ns.name}") return diff --git a/scripts/spartan/world.py b/scripts/spartan/world.py index fe06d07..4b6c57a 100644 --- a/scripts/spartan/world.py +++ b/scripts/spartan/world.py @@ -725,7 +725,7 @@ class World: msg = f"worker '{worker.label}' is online" logger.info(msg) gradio.Info("Distributed: "+msg) - worker.set_state(State.IDLE) + worker.set_state(State.IDLE, expect_cycle=True) else: msg = f"worker '{worker.label}' is unreachable" logger.info(msg)