1
0
Fork 0
mirror of synced 2024-06-02 10:44:40 +12:00

Redirect stdout and stderr to os.devnull if we are in a frozen GUI application form

This commit is contained in:
Stelios Tsampas 2022-09-10 22:05:00 +03:00
parent 3192bdff3f
commit cbf4c38564

View file

@ -117,4 +117,12 @@ if __name__ == "__main__":
if "__compiled__" not in globals():
sys.path.insert(0, str(pathlib.Path(__file__).parents[1].absolute()))
# If we are on Windows, and we are in a "compiled" GUI application form
# stdout (and stderr?) will be None. So to avoid `'NoneType' object has no attribute 'write'`
# errors, redirect both of them to devnull
if os.name == "nt" and (getattr(sys, "frozen", False) or ("__compiled__" in globals())):
f = open(os.devnull, 'w')
sys.stdout = f
sys.stderr = f
main()