From c3492072279278da3ff2ded02b4bb7b1606c55db Mon Sep 17 00:00:00 2001 From: Loren Eteval Date: Sun, 8 Oct 2023 19:29:48 +0800 Subject: [PATCH] Add stdout/stderr redirect guard for pythonw.exe Signed-off-by: Loren Eteval --- Furious/Core/Core.py | 23 ++++++++++++++++++++++- 1 file changed, 22 insertions(+), 1 deletion(-) diff --git a/Furious/Core/Core.py b/Furious/Core/Core.py index a183cdf..f420fde 100644 --- a/Furious/Core/Core.py +++ b/Furious/Core/Core.py @@ -129,12 +129,33 @@ class Core: class StdoutRedirectHelper: TemporaryDir = QtCore.QTemporaryDir() + @staticmethod + def isRealFile(file): + if not hasattr(file, 'fileno'): + return False + + try: + tmp = os.dup(file.fileno()) + except Exception: + # Any non-exit exceptions + + return False + else: + os.close(tmp) + + return True + @staticmethod def launch(msgQueue, entrypoint): if not callable(entrypoint): return - if not StdoutRedirectHelper.TemporaryDir.isValid(): + if ( + not StdoutRedirectHelper.TemporaryDir.isValid() + # pythonw.exe + or not StdoutRedirectHelper.isRealFile(sys.__stdout__) + or not StdoutRedirectHelper.isRealFile(sys.__stderr__) + ): # Call entrypoint directly entrypoint()