Skip to content

Commit

Permalink
Fix ModuleContainer.shutdown() and its usages
Browse files Browse the repository at this point in the history
  • Loading branch information
borzunov committed Oct 11, 2022
1 parent b5d54f4 commit 9191963
Showing 1 changed file with 5 additions and 8 deletions.
13 changes: 5 additions & 8 deletions src/server/server.py
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ def __init__(
prefetch_batches: int = 1,
sender_threads: int = 1,
mean_block_selection_delay: float = 0.5,
mean_balance_check_period: float = 60, # TODO:
mean_balance_check_period: float = 300, # TODO:
use_auth_token: Optional[str] = None,
load_in_8bit: bool = False,
*,
Expand Down Expand Up @@ -175,6 +175,7 @@ def run(self):

while True:
timeout = random.random() * 2 * self.mean_balance_check_period
# TODO: Follow ModuleContainer status (to restart/stop if it crashes)
if self.stop.wait(timeout):
return
if self._should_choose_other_blocks():
Expand Down Expand Up @@ -251,7 +252,7 @@ def __init__(
def run(self):
"""
Runs ModuleContainer in the current thread. Initializes dht if necessary, starts connection handlers,
runs hivemind.Runtime (self.runtime) to process incoming requests.
runs Runtime (self.runtime) to process incoming requests.
"""
logger.info(f"Serving {len(self.module_backends)} blocks:")
for expert_name, backend in self.module_backends.items():
Expand All @@ -272,10 +273,7 @@ def run(self):
process.start()
process.ready.result()

try:
self.runtime.run()
finally:
self.shutdown()
self.runtime.run()

# noinspection PyMethodOverriding
@classmethod
Expand Down Expand Up @@ -414,8 +412,7 @@ def shutdown(self):
self.ready.clear()

for process in self.conn_handlers:
process.terminate()
process.join()
process.shutdown()
logger.debug("Connection handlers terminated")

if self.checkpoint_saver is not None:
Expand Down

0 comments on commit 9191963

Please sign in to comment.