From dda9f3e734c239b8c45d957cb9d84a53c66b5240 Mon Sep 17 00:00:00 2001 From: teknium1 Date: Sun, 1 Mar 2026 16:14:57 -0800 Subject: [PATCH] fix(process_registry): ensure unbuffered output for subprocesses Updated the environment variables for subprocess execution in the ProcessRegistry class to set PYTHONUNBUFFERED to "1". This change ensures that output from Python scripts is unbuffered, allowing for real-time visibility of progress during background execution. Adjusted both the pty and background process spawning methods to use the new environment configuration. --- tools/process_registry.py | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/tools/process_registry.py b/tools/process_registry.py index cbc0dd853e..a74e2b65c5 100644 --- a/tools/process_registry.py +++ b/tools/process_registry.py @@ -146,10 +146,12 @@ class ProcessRegistry: try: import ptyprocess user_shell = os.environ.get("SHELL") or shutil.which("bash") or "/bin/bash" + pty_env = os.environ | (env_vars or {}) + pty_env["PYTHONUNBUFFERED"] = "1" pty_proc = ptyprocess.PtyProcess.spawn( [user_shell, "-lic", command], cwd=session.cwd, - env=os.environ | (env_vars or {}), + env=pty_env, dimensions=(30, 120), ) session.pid = pty_proc.pid @@ -182,11 +184,16 @@ class ProcessRegistry: # Use the user's login shell for consistency with LocalEnvironment -- # ensures rc files are sourced and user tools are available. user_shell = os.environ.get("SHELL") or shutil.which("bash") or "/bin/bash" + # Force unbuffered output for Python scripts so progress is visible + # during background execution (libraries like tqdm/datasets buffer when + # stdout is a pipe, hiding output from process(action="poll")). + bg_env = os.environ | (env_vars or {}) + bg_env["PYTHONUNBUFFERED"] = "1" proc = subprocess.Popen( [user_shell, "-lic", command], text=True, cwd=session.cwd, - env=os.environ | (env_vars or {}), + env=bg_env, encoding="utf-8", errors="replace", stdout=subprocess.PIPE,