From 97a60363f480ecf3612e7696a3c6b910a3a8f3fe Mon Sep 17 00:00:00 2001 From: sepandhaghighi Date: Thu, 29 Aug 2024 03:54:02 +0430 Subject: [PATCH 1/3] feat : _kill_play_process method added --- nava/thread.py | 32 +++++++++++++++++++++----------- 1 file changed, 21 insertions(+), 11 deletions(-) diff --git a/nava/thread.py b/nava/thread.py index 440e85d..4e08a18 100644 --- a/nava/thread.py +++ b/nava/thread.py @@ -28,6 +28,25 @@ def __init__(self, loop, engine, *args, **kwargs): self._engine = engine self._nava_exception = None + def _kill_play_process(self): + """ + Kill play process. + + :return: None + """ + if self._play_process is not None: + try: + self._play_process.stdout.close() + self._play_process.stdin.close() + self._play_process.stderr.close() + self._play_process.kill() + self._play_process.terminate() + except ProcessLookupError: + pass + finally: + self._play_process.wait() + + def run(self): """ Run target function. @@ -46,6 +65,7 @@ def run(self): break except Exception: # pragma: no cover self._nava_exception = SOUND_FILE_PLAY_ERROR + self._kill_play_process() raise NavaBaseError(SOUND_FILE_PLAY_ERROR) def stop(self): @@ -59,14 +79,4 @@ def stop(self): import winsound winsound.PlaySound(None, winsound.SND_PURGE) else: - if self._play_process is not None: - try: - self._play_process.stdout.close() - self._play_process.stdin.close() - self._play_process.stderr.close() - self._play_process.kill() - self._play_process.terminate() - except ProcessLookupError: - pass - finally: - self._play_process.wait() + self._kill_play_process() From 36127cdad2881ea3feaadbb8217cdbb7a04fb7be Mon Sep 17 00:00:00 2001 From: sepandhaghighi Date: Thu, 29 Aug 2024 03:54:51 +0430 Subject: [PATCH 2/3] fix : autopep8 --- nava/thread.py | 1 - 1 file changed, 1 deletion(-) diff --git a/nava/thread.py b/nava/thread.py index 4e08a18..3ae5a6b 100644 --- a/nava/thread.py +++ b/nava/thread.py @@ -46,7 +46,6 @@ def _kill_play_process(self): finally: self._play_process.wait() - def run(self): """ Run target function. From b4c848dcc1fa47e69dbc35e7bb279af341f06463 Mon Sep 17 00:00:00 2001 From: sepandhaghighi Date: Tue, 10 Sep 2024 18:36:26 +0430 Subject: [PATCH 3/3] fix : _kill_play_process function updated --- nava/thread.py | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/nava/thread.py b/nava/thread.py index 3ae5a6b..7329fb8 100644 --- a/nava/thread.py +++ b/nava/thread.py @@ -28,10 +28,12 @@ def __init__(self, loop, engine, *args, **kwargs): self._engine = engine self._nava_exception = None - def _kill_play_process(self): + def _kill_play_process(self, wait=True): """ Kill play process. + :param wait: wait flag + :type wait: bool :return: None """ if self._play_process is not None: @@ -44,7 +46,8 @@ def _kill_play_process(self): except ProcessLookupError: pass finally: - self._play_process.wait() + if wait: + self._play_process.wait() def run(self): """ @@ -64,7 +67,7 @@ def run(self): break except Exception: # pragma: no cover self._nava_exception = SOUND_FILE_PLAY_ERROR - self._kill_play_process() + self._kill_play_process(wait=False) raise NavaBaseError(SOUND_FILE_PLAY_ERROR) def stop(self):