I need threading for a voip app that I am writing in python and PyQt5. This thread does the playing ringTone job.
But I don't know how to stop this thread from playing, I need a way like terminate
in Process to kill the thread clean and easy but I couldn't find that. I have to mention that I can't use Process and multiProcessing (there is a problem that I couldn't find a way to show that in minimal way).
Here is a minimalized code for my problem:
import playsound
# from multiprocessing import Process
from playsound import playsound
from threading import Thread
class Test:
def __init__(self):
self.ringTone = True
def ringTonePlay(self):
while self.ringTone:
playsound("ring_tone.wav")
def testFunction(self):
self.p1 = Thread(target = self.ringTonePlay)
self.p1.start()
def stopFunction(self):
self.ringTone = False
test = Test()
test.testFunction()
test.stopFunction()
When I call stopFunction
function it still keeps ringing.
What way you suggest for terminating the playing thread??