From 9ccafcc0d533f606dbe58ea0922eef04647a2fdf Mon Sep 17 00:00:00 2001 From: eric Date: Thu, 19 Mar 2026 02:50:52 -0500 Subject: [PATCH] 's' --- demucs_pipeline.py | 22 +++++++++++++++++++++- 1 file changed, 21 insertions(+), 1 deletion(-) diff --git a/demucs_pipeline.py b/demucs_pipeline.py index 716b20f..f05c3e5 100644 --- a/demucs_pipeline.py +++ b/demucs_pipeline.py @@ -285,7 +285,7 @@ def run_demucs_pipeline( ffmpeg_out_cmd, stdin=subprocess.PIPE, stdout=subprocess.DEVNULL, - stderr=subprocess.DEVNULL, + stderr=subprocess.PIPE, bufsize=1024 * 1024, ) @@ -331,6 +331,20 @@ def run_demucs_pipeline( reader_t.daemon = True reader_t.start() + # 监控 proc_out 的 stderr(推流到 YouTube,错误必须可见) + def _proc_out_stderr_reader(): + try: + for line in iter(proc_out.stderr.readline, b""): + if line: + decoded = line.decode("utf-8", errors="replace").strip() + if decoded: + print(f"[YouTube推流] {decoded}") + except Exception: + pass + + proc_out_reader_t = threading.Thread(target=_proc_out_stderr_reader, daemon=True) + proc_out_reader_t.start() + start_time = last_frame_time = time.time() proc_v.last_out_ts = time.time() @@ -338,6 +352,10 @@ def run_demucs_pipeline( try: line = stderr_q.get(timeout=stderr_queue_timeout) except queue.Empty: + # 若 proc_out(推流进程)已异常退出,立即报告 + if proc_out.poll() is not None and proc_out.returncode != 0: + print(f"[ERROR] YouTube 推流进程已退出,返回码: {proc_out.returncode}") + break if time.time() - getattr(proc_v, "last_out_ts", time.time()) > stale_output_seconds: print("[WARN] 长时间无任何日志,强制重启进程") break @@ -378,6 +396,8 @@ def run_demucs_pipeline( traceback.print_exc() finally: stop_event.set() + if proc_out is not None and proc_out.poll() is not None and proc_out.returncode != 0: + print(f"[INFO] YouTube 推流进程退出码: {proc_out.returncode}") cleanup_proc_fn(proc_v) cleanup_proc_fn(proc_a) cleanup_proc_fn(proc_out)