From dccf4f45ef86260ba883b4602c137e65aa8bf107 Mon Sep 17 00:00:00 2001 From: locpham Date: Sun, 9 Aug 2026 00:58:22 +0000 Subject: [PATCH] =?UTF-8?q?FIX:=20windowed=20app=20(console=3DFalse)=20sys?= =?UTF-8?q?.stderr=3DNone=20->=20uvicorn=20logging=20crash=20isatty=20?= =?UTF-8?q?=E2=80=94=20thay=20bang=20devnull?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- desktop_engine.py | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/desktop_engine.py b/desktop_engine.py index d0f63bc..9ff3bf0 100644 --- a/desktop_engine.py +++ b/desktop_engine.py @@ -37,6 +37,16 @@ def _parent_alive(pid): def main(): os.environ.setdefault("SF_DESKTOP", "1") + + # Windowed app (engine.spec console=False): Windows khong tao console -> + # sys.stdout/sys.stderr = None -> uvicorn logging crash + # ('NoneType' object has no attribute 'isatty'). Thay bang file rong de + # uvicorn (StreamHandler/isatty) luon co stream hop le. + if sys.stdout is None: + sys.stdout = open(os.devnull, "w") + if sys.stderr is None: + sys.stderr = open(os.devnull, "w") + port = _pick_port() os.environ["SF_PORT"] = str(port)