From 19918b5bdc8bee939c25fb2c62e65a3d85534ce7 Mon Sep 17 00:00:00 2001 From: Loren Eteval Date: Wed, 18 Oct 2023 16:40:25 +0800 Subject: [PATCH] Fix core exitcallback called multiple times Signed-off-by: Loren Eteval --- Furious/Core/Core.py | 30 +++++++++++++++++------------- 1 file changed, 17 insertions(+), 13 deletions(-) diff --git a/Furious/Core/Core.py b/Furious/Core/Core.py index 2afbb92..0c88854 100644 --- a/Furious/Core/Core.py +++ b/Furious/Core/Core.py @@ -83,21 +83,25 @@ class Core: return False def checkAlive(self): - assert isinstance(self._process, multiprocessing.Process) + if isinstance(self._process, multiprocessing.Process): + if self._process.is_alive(): + return True + else: + logger.error( + f'{self.name()} stopped unexpectedly with exitcode {self._process.exitcode}' + ) - if self._process.is_alive(): - return True + self._stdoutTimer.stop() + self._daemonTimer.stop() + + if callable(self._exitCallback): + self._exitCallback(self._process.exitcode) + + # Reset internal process + self._process = None + + return False else: - logger.error( - f'{self.name()} stopped unexpectedly with exitcode {self._process.exitcode}' - ) - - self._stdoutTimer.stop() - self._daemonTimer.stop() - - if callable(self._exitCallback): - self._exitCallback(self._process.exitcode) - return False def start(self, *args, **kwargs):