Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Process bug #54

Draft
wants to merge 3 commits into
base: dev
Choose a base branch
from
Draft
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
34 changes: 23 additions & 11 deletions nava/thread.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,27 @@ def __init__(self, loop, engine, *args, **kwargs):
self._engine = engine
self._nava_exception = None

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:
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:
if wait:
self._play_process.wait()

def run(self):
"""
Run target function.
Expand All @@ -46,6 +67,7 @@ def run(self):
break
except Exception: # pragma: no cover
self._nava_exception = SOUND_FILE_PLAY_ERROR
self._kill_play_process(wait=False)
raise NavaBaseError(SOUND_FILE_PLAY_ERROR)

def stop(self):
Expand All @@ -59,14 +81,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()
Loading