I have a function that plays a sound file in loops in separate thread (taken from the answer of this question), and my function get as an argument the name of the file it should play.
def loop_play(sound_file):
audio = AudioSegment.from_file(sound_file)
while is_playing:
play(audio)
def play_sound(sound_file):
global is_playing
global sound_thread
if not is_playing:
is_playing = True
sound_thread = Thread(target=loop_play,args=[sound_file])
sound_thread.daemon = True
sound_thread.start()
Every time I call play_sound
, I overwrite sound_thread
and create a new Thread. What happens to the old one? Is it still running in the background? Is there a way to terminate it?