mirror of
https://github.com/comfyanonymous/ComfyUI.git
synced 2026-05-28 01:47:32 +08:00
fix: guard log flush against OSError
This commit is contained in:
parent
f9f54cae42
commit
8f49e3cd2a
@ -66,7 +66,10 @@ class LogInterceptor(io.TextIOWrapper):
|
|||||||
super().write(data)
|
super().write(data)
|
||||||
|
|
||||||
def flush(self):
|
def flush(self):
|
||||||
super().flush()
|
try:
|
||||||
|
super().flush()
|
||||||
|
except OSError:
|
||||||
|
pass
|
||||||
for cb in self._flush_callbacks:
|
for cb in self._flush_callbacks:
|
||||||
cb(self._logs_since_flush)
|
cb(self._logs_since_flush)
|
||||||
self._logs_since_flush = []
|
self._logs_since_flush = []
|
||||||
|
|||||||
26
tests-unit/app_test/logger_test.py
Normal file
26
tests-unit/app_test/logger_test.py
Normal file
@ -0,0 +1,26 @@
|
|||||||
|
import io
|
||||||
|
|
||||||
|
from app.logger import LogInterceptor
|
||||||
|
|
||||||
|
|
||||||
|
class FlushErrorBuffer(io.BytesIO):
|
||||||
|
def flush(self):
|
||||||
|
raise OSError(22, "Invalid argument")
|
||||||
|
|
||||||
|
|
||||||
|
class FlushErrorStream:
|
||||||
|
buffer = FlushErrorBuffer()
|
||||||
|
encoding = "utf-8"
|
||||||
|
line_buffering = False
|
||||||
|
|
||||||
|
|
||||||
|
def test_log_interceptor_flush_ignores_oserror_and_runs_callbacks():
|
||||||
|
interceptor = LogInterceptor(FlushErrorStream())
|
||||||
|
interceptor._logs_since_flush = [{"m": "message"}]
|
||||||
|
flushed_logs = []
|
||||||
|
|
||||||
|
interceptor.on_flush(lambda logs: flushed_logs.append(list(logs)))
|
||||||
|
interceptor.flush()
|
||||||
|
|
||||||
|
assert flushed_logs == [[{"m": "message"}]]
|
||||||
|
assert interceptor._logs_since_flush == []
|
||||||
Loading…
Reference in New Issue
Block a user