Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix deadlock issue in FFmpeg subprocess by ensuring stderr is consumed #257

Merged
merged 1 commit into from
Jul 19, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 13 additions & 0 deletions whisper_live/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
import shutil
import wave

import logging
import numpy as np
import pyaudio
import threading
Expand Down Expand Up @@ -431,6 +432,8 @@ def process_hls_stream(self, hls_url, save_file):

def handle_ffmpeg_process(self, process, stream_type):
print(f"[INFO]: Connecting to {stream_type} stream...")
stderr_thread = threading.Thread(target=self.consume_stderr, args=(process,))
stderr_thread.start()
try:
# Process the stream
while True:
Expand Down Expand Up @@ -477,6 +480,16 @@ def get_hls_ffmpeg_process(self, hls_url, save_file):

return process

def consume_stderr(self, process):
"""
Consume and log the stderr output of a process in a separate thread.

Args:
process (subprocess.Popen): The process whose stderr output will be logged.
"""
for line in iter(process.stderr.readline, b""):
logging.debug(f'[STDERR]: {line.decode()}')

def save_chunk(self, n_audio_file):
"""
Saves the current audio frames to a WAV file in a separate thread.
Expand Down
Loading