1

I have a UI program that records audio from microphone and speakers with a loop in another thread that writes to file what is recorded, everything goes well until I try to close the GUI, but the thread doesn't stop, as Sublime doesnt show '[Finished in Xs.]'. The thread stops when I click the button 'Stop' tho. This is the main code on the problem:

thread = Thread(target=self.record_and_recognize, args=(args, callback))
thread.start()
def record_and_recognize(self, args, callback_func):
    self.labeltext.set('Recording...')
    with sf.SoundFile(args.filename, mode='w', samplerate=args.samplerate,
                      channels=args.channels, subtype=args.subtype) as file:
            with sd.InputStream(samplerate=args.samplerate, device=args.device,
                                channels=args.channels, callback=callback_func):
                # Thread loop that writes sound to file until stopped
                while self.recording:
                    file.write(self.progression.get())

What can I do?

  • Does this answer your question? [Killing all processes and threads in python3.X](https://stackoverflow.com/questions/62873234/killing-all-processes-and-threads-in-python3-x) – stovfl Jul 29 '20 at 18:16
  • Actually I new the answer myself, the reason I asked the question is that I got banned on StackO :'( and I hoped someone will upvote my question to get unbanned. –  Jul 29 '20 at 18:42

0 Answers0