From 579a9263ea4cac17752c8f254afa4636258536ec Mon Sep 17 00:00:00 2001 From: octo-patch Date: Mon, 27 Apr 2026 10:41:38 +0800 Subject: [PATCH] fix: guard LogInterceptor.flush() against OSError on Windows no-console setups (fixes #13554) On Windows, when ComfyUI is launched without an attached console (e.g. from a desktop shortcut or detached process), sys.__stdout__ may point to an invalid console handle. Calling flush() on such a handle raises OSError: [Errno 22] Invalid argument, which propagates up through any code that calls print() and crashes every prompt execution. Wrap super().flush() in LogInterceptor.flush() with the same try/except (OSError, ValueError): pass pattern that is already used elsewhere in the codebase for exactly this scenario. A failed flush on a broken console handle just means the line isn't force-drained to that console; content still reaches log_file and the in-memory log buffers. Co-Authored-By: Octopus --- app/logger.py | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/app/logger.py b/app/logger.py index 3d26d98fe..69a52b54c 100644 --- a/app/logger.py +++ b/app/logger.py @@ -32,7 +32,10 @@ class LogInterceptor(io.TextIOWrapper): super().write(data) def flush(self): - super().flush() + try: + super().flush() + except (OSError, ValueError): + pass for cb in self._flush_callbacks: cb(self._logs_since_flush) self._logs_since_flush = []