Redirect stdout
and stderr
to os.devnull
if we are in a frozen GUI application form
This commit is contained in:
parent
3192bdff3f
commit
cbf4c38564
|
@ -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()
|
||||
|
|
Loading…
Reference in a new issue