From 94890d64186f5c13416fb4e5e78761ef43f23141 Mon Sep 17 00:00:00 2001 From: FlintyLemming Date: Sat, 28 Feb 2026 11:42:57 +0800 Subject: [PATCH] =?UTF-8?q?=F0=9F=90=9B=20fix(av1-transfer):=20silently=20?= =?UTF-8?q?fall=20back=20when=20preexec=5Ffn=20exec=20fails=20in=20multith?= =?UTF-8?q?readed=20context?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit GIL contention after fork in ThreadPoolExecutor can cause os.execvp to fail. Catch the exception so subprocess proceeds with its own exec, keeping transcoding functional even if process renaming fails. Co-Authored-By: Claude Sonnet 4.6 --- av1-transfer/main.py | 14 +++++++++----- 1 file changed, 9 insertions(+), 5 deletions(-) diff --git a/av1-transfer/main.py b/av1-transfer/main.py index fff68b3..30d4322 100644 --- a/av1-transfer/main.py +++ b/av1-transfer/main.py @@ -132,15 +132,19 @@ def transcode_one_file(file_info, overall_bar, slot_bars, slot_queue, process_na str_args = [str(a) for a in ffmpeg_args] if process_name: - # fork 后、subprocess 执行 exec 之前,用 os.execvp 替换进程: - # - execvp 通过 PATH 查找 ffmpeg(规避 execve 直接调用 symlink 的问题) - # - argv[0] 设为别名,ps/top 显示别名而非 ffmpeg - # - subprocess 设好的 stdout/stderr pipe 已继承,无需额外处理 + # 尝试在 fork 后、subprocess exec 之前用 os.execvp 替换进程(设 argv[0] 为别名) + # 多线程环境下 GIL 可能导致 execvp 失败;失败时静默返回, + # subprocess 会接着正常执行 ffmpeg,转码不受影响 _pname = process_name _args = str_args + def _try_exec(): + try: + os.execvp("ffmpeg", [_pname] + _args) + except Exception: + pass proc = subprocess.Popen( ["ffmpeg"] + str_args, - preexec_fn=lambda: os.execvp("ffmpeg", [_pname] + _args), + preexec_fn=_try_exec, stdout=subprocess.PIPE, stderr=subprocess.PIPE, )