|
@@ -306,7 +306,7 @@ class DecentralizedAverager(mp.Process, ServicerBase):
|
|
|
def shutdown(self) -> None:
|
|
|
"""Shut down the averager process"""
|
|
|
if self.is_alive():
|
|
|
- self._outer_pipe.send(("_shutdown", [None], {})) # shut down the daemon process
|
|
|
+ self._outer_pipe.send(("_shutdown", [self.shutdown_timeout], {})) # shut down the daemon process
|
|
|
self._inner_pipe.send(("_SHUTDOWN", None)) # shut down background thread in master
|
|
|
self.join(self.shutdown_timeout)
|
|
|
if self.is_alive():
|
|
@@ -315,11 +315,11 @@ class DecentralizedAverager(mp.Process, ServicerBase):
|
|
|
else:
|
|
|
logger.exception("Averager shutdown has no effect: the process is already not alive")
|
|
|
|
|
|
- async def _shutdown(self) -> None:
|
|
|
+ async def _shutdown(self, timeout: Optional[DHTExpiration]) -> None:
|
|
|
remaining_tasks = set()
|
|
|
for group in self._running_groups.values():
|
|
|
remaining_tasks.update(group.finalize(cancel=True))
|
|
|
- await asyncio.gather(*remaining_tasks)
|
|
|
+ await asyncio.wait_for(asyncio.gather(*remaining_tasks), timeout)
|
|
|
|
|
|
def __del__(self):
|
|
|
if self._parent_pid == os.getpid() and self.is_alive():
|