Skip to content

Commit

Permalink
fix : use NavaThread instead of Thread
Browse files Browse the repository at this point in the history
  • Loading branch information
sepandhaghighi committed Jan 16, 2024
1 parent 25892c1 commit 2e83244
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 9 deletions.
7 changes: 3 additions & 4 deletions nava/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,9 @@
"""Nava modules."""
from .params import NAVA_VERSION
from .errors import NavaBaseError
from .functions import play, cleanup_processes

from .functions import play, stop, stop_all
import atexit
# Async play processes clean up
atexit.register(cleanup_processes)

atexit.register(stop_all)

__version__ = NAVA_VERSION
10 changes: 5 additions & 5 deletions nava/functions.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
import os
import shlex
from functools import wraps
import threading
from .thread import NavaThread
from .params import OVERVIEW
from .params import SOUND_FILE_PLAY_ERROR, SOUND_FILE_EXIST_ERROR
from .params import SOUND_FILE_PATH_TYPE_ERROR
Expand All @@ -18,7 +18,7 @@ def stop(sound_id):
def stop_all():
for thread in params._play_threads_map.values():
thread.stop()

def sound_id_gen():
params._play_threads_counter +=1
sound_id = params._play_threads_counter + 1000
Expand Down Expand Up @@ -84,7 +84,7 @@ def __play_win(sound_path, is_async=True):
play_flags = winsound.SND_FILENAME | (is_async & winsound.SND_ASYNC)

if is_async:
sound_thread = threading.Thread(target=__play_win_by_flags,
sound_thread = NavaThread(target=__play_win_by_flags,
args=(sound_path, play_flags),
daemon=True)
sound_thread.start()
Expand Down Expand Up @@ -121,7 +121,7 @@ def __play_linux(sound_path, is_async=True):
:return: None or sound thread (depending on async flag)
"""
if is_async:
sound_thread = threading.Thread(target=__play_sync_linux,
sound_thread = NavaThread(target=__play_sync_linux,
args=(sound_path,),
daemon=True)
sound_thread.start()
Expand Down Expand Up @@ -162,7 +162,7 @@ def __play_mac(sound_path, is_async=True):
:return: None or sound thread, depending on the flag
"""
if is_async:
sound_thread = threading.Thread(target=__play_sync_mac,
sound_thread = NavaThread(target=__play_sync_mac,
args=(sound_path,),
daemon=True)
sound_thread.start()
Expand Down

0 comments on commit 2e83244

Please sign in to comment.