Comfy-Org / Comfy-Org/ComfyUI-Manager

OSError: [Errno 22] Invalid argument on Windows when flushing stderr

Open
#2,458 0 comments 3 reactions 0 assignees View on GitHub
Dominant language
Python
Stars
16.1k
Forks
2.5k
Avg merge
5d 4h
Merged PRs (30d)
13

Description

## Description
ComfyUI crashes on Windows (Desktop app) with `OSError: [Errno 22] Invalid argument` when the tqdm progress bar tries to flush stderr during sampling.

## Environment
- OS: Windows 11
- ComfyUI Version: 0.6.0
- ComfyUI-Manager: 4.0.4
- Python: 3.12.11
- PyTorch: 2.8.0+cu129
- GPU: NVIDIA GeForce RTX 5080
- Using ComfyUI Desktop app

## Error Stack Trace
```
File "comfyui_manager/prestartup_script.py", line 346, in flush
original_stderr.flush()
File "C:\Users\...\ComfyUI\app\logger.py", line 35, in flush
super().flush()
OSError: [Errno 22] Invalid argument
```

## Full traceback
The error occurs in the sampling loop when tqdm tries to display progress:
```
File "comfy/k_diffusion/sampling.py", line 188, in sample_euler
for i in trange(len(sigmas) - 1, disable=disable):
File "tqdm/std.py", line 448, in status_printer
getattr(sys.stderr, 'flush', lambda: None)()
File "comfyui_manager/prestartup_script.py", line 346, in flush
original_stderr.flush()
OSError: [Errno 22] Invalid argument
```

## Cause
The `flush()` method in `prestartup_script.py` line 342-346 doesn't handle the case where `original_stderr` is a special Windows handle (from ComfyUI Desktop app) that doesn't support the flush operation.

## Suggested Fix
Add try-except around the flush call in `prestartup_script.py`:

```python
with std_log_lock:
try:
if self.is_stdout:
original_stdout.flush()
else:
original_stderr.flush()
except OSError:
pass # Ignore flush errors on Windows
```

## Workaround
Users can manually apply this fix to `prestartup_script.py` to prevent the crash.

Contributor guide

No contributing guide indexed for this repository

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.