fix: 修復 win python install.py

This commit is contained in:
alex
2025-12-16 12:29:50 +08:00
parent 3d27d44676
commit 9471a981e3

View File

@@ -357,6 +357,27 @@ def op_run_command(op: Dict[str, Any], ctx: Dict[str, Any]) -> None:
stderr_lines: List[str] = [] stderr_lines: List[str] = []
# Read stdout and stderr in real-time # Read stdout and stderr in real-time
if sys.platform == "win32":
# On Windows, use threads instead of selectors (pipes aren't selectable)
import threading
def read_output(pipe, lines, file=None):
for line in iter(pipe.readline, ''):
lines.append(line)
print(line, end="", flush=True, file=file)
pipe.close()
stdout_thread = threading.Thread(target=read_output, args=(process.stdout, stdout_lines))
stderr_thread = threading.Thread(target=read_output, args=(process.stderr, stderr_lines, sys.stderr))
stdout_thread.start()
stderr_thread.start()
stdout_thread.join()
stderr_thread.join()
process.wait()
else:
# On Unix, use selectors for more efficient I/O
import selectors import selectors
sel = selectors.DefaultSelector() sel = selectors.DefaultSelector()
sel.register(process.stdout, selectors.EVENT_READ) # type: ignore[arg-type] sel.register(process.stdout, selectors.EVENT_READ) # type: ignore[arg-type]