From 0b2a226dc8f942588c2f75447c8ef905ceb4fa83 Mon Sep 17 00:00:00 2001 From: Damien Elmes Date: Sat, 9 Apr 2022 16:48:06 +1000 Subject: [PATCH] Add mock stdout/stderr for console=False case on Windows PyInstaller provided a NulWriter when running in GUI mode, but stdout/ stderr now default to None with PyOxidizer. Fixes #1786 --- qt/aqt/__init__.py | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/qt/aqt/__init__.py b/qt/aqt/__init__.py index e62f2afd2..bb070ea67 100644 --- a/qt/aqt/__init__.py +++ b/qt/aqt/__init__.py @@ -59,8 +59,10 @@ try: sys.stdout.reconfigure(encoding="utf-8") # type: ignore sys.stderr.reconfigure(encoding="utf-8") # type: ignore except AttributeError: - # on Windows without console, NullWriter doesn't support this - pass + if is_win: + # On Windows without console; add a mock writer. The stderr + # writer will be overwritten when ErrorHandler is initialized. + sys.stderr = sys.stdout = open(os.devnull, "w", encoding="utf8") appVersion = _version appWebsite = "https://apps.ankiweb.net/"