FIX: windowed app (console=False) sys.stderr=None -> uvicorn logging crash isatty — thay bang devnull

This commit is contained in:
2026-08-09 00:58:22 +00:00
parent 9099529403
commit dccf4f45ef
+10
View File
@@ -37,6 +37,16 @@ def _parent_alive(pid):
def main(): def main():
os.environ.setdefault("SF_DESKTOP", "1") 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() port = _pick_port()
os.environ["SF_PORT"] = str(port) os.environ["SF_PORT"] = str(port)