KoljaB / RealtimeSTT

A robust, efficient, low-latency speech-to-text library with advanced voice activity detection, wake word activation and instant transcription.
MIT License
2.09k stars 190 forks source link

shutdown hanging on thread join #103

Open JayDeezus opened 3 months ago

JayDeezus commented 3 months ago

https://github.com/KoljaB/RealtimeSTT/blob/d02be1f6a6757f518864deb3f35a53b6b3563f21/RealtimeSTT/audio_recorder.py#L1209

I'm trying to track down why on my system sometimes (usually) when I Ctrl-C to shut down my app shutdown will hang on the aforementioned line. I tried subclassing and copying the shutdown method and inserting print statements to see how far it gets and it's getting hung while trying to join the recording_thread.

At this point, I'm just trying to separate concerns, so am trying to figure out if I can just stop the task in the thread and get this to join and move on somehow. Currently investigating.

bilalshafim commented 2 months ago

I have noticed similar behaviour. I implemented a simple client and server. To test it out, I added print statements to a if connection is none statement in the realtime callback function and after a client disconnects and shutdown is called, the callback keeps on printing and I have had to kill the server process for it to stop. With multiple clients, this will cause huge issues of course.

I am still trying to find the issue as well but I think adding a is_shutdown_state type check and breaking the while loop in _realtime_worker might solve this since the callback does not stop and is called from _realtime_worker. Will test this out tomorrow and update here.

KoljaB commented 2 months ago

Please replace this line with

                    try:
                        data = self.audio_queue.get(timeout=0.1)
                    except queue.Empty:
                        if not self.is_running:
                            break
                        continue

for a quick fix. Next version with a bugfix will be released end of the week I guess.