Skip to content

Commit

Permalink
Configure whether the background thread is daemon or not
Browse files Browse the repository at this point in the history
  • Loading branch information
sjmikler committed Nov 10, 2024
1 parent 0d4545e commit 06c7bcf
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 3 deletions.
6 changes: 4 additions & 2 deletions playsound3/playsound3.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,14 +25,16 @@ class PlaysoundException(Exception):
pass


def playsound(sound, block: bool = True, backend: Union[str, None] = None) -> None:
def playsound(sound, block: bool = True, backend: Union[str, None] = None, daemon=True) -> None:
"""Play a sound file using an audio backend availabile in your system.
Args:
sound: Path or URL to the sound file. Can be a string or pathlib.Path.
block: If True, the function will block execution until the sound finishes playing.
If False, sound will play in a background thread.
backend: Name of the audio backend to use. Use None for automatic selection.
daemon: If True, and `block` is True, the background thread will be a daemon thread.
This means that the thread will stay alive even after the main program exits.
"""
if backend is None:
_play = _PLAYSOUND_DEFAULT_BACKEND
Expand All @@ -45,7 +47,7 @@ def playsound(sound, block: bool = True, backend: Union[str, None] = None) -> No
if block:
_play(path)
else:
Thread(target=_play, args=(path,), daemon=True).start()
Thread(target=_play, args=(path,), daemon=daemon).start()


def _download_sound_from_web(link, destination):
Expand Down
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ build-backend = "hatchling.build"

[project]
name = "playsound3"
version = "2.2.3"
version = "2.3.0"
requires-python = ">=3.7"
authors = [
{ name = "Szymon Mikler", email = "[email protected]" },
Expand Down

0 comments on commit 06c7bcf

Please sign in to comment.