force stdout/stderr encoding to utf8

As a GUI app, Anki only uses these for debugging info, and we've been
bitten numerous times in the past by bugs caused by printing Unicode
when the console only supported ASCII. An ens var might have been
a better approach, but Pyinstaller does not support defining them before
Python is initialized from what I can tell.

Latest issue:
https://forums.ankiweb.net/t/crashing-anki-version-2-1-29-bbff62bf/1650
This commit is contained in:
Damien Elmes 2020-08-01 11:30:16 +10:00
parent 07594bc375
commit a8139ebb40

View file

@ -24,6 +24,11 @@ from aqt.utils import locale_dir
assert anki.buildinfo.buildhash == aqt.buildinfo.buildhash
# we want to be able to print unicode debug info to console without
# fear of a traceback on systems with the console set to ASCII
sys.stdout.reconfigure(encoding="utf-8") # type: ignore
sys.stderr.reconfigure(encoding="utf-8") # type: ignore
appVersion = _version
appWebsite = "https://apps.ankiweb.net/"
appChanges = "https://apps.ankiweb.net/docs/changes.html"