src/eric7/EricWidgets/EricErrorMessage.py

branch
eric7
changeset 11026
53d18eb2062d
parent 11006
a671918232f3
child 11035
e1e1d6e317c7
--- a/src/eric7/EricWidgets/EricErrorMessage.py	Thu Oct 31 20:01:36 2024 +0100
+++ b/src/eric7/EricWidgets/EricErrorMessage.py	Fri Nov 01 10:34:41 2024 +0100
@@ -8,6 +8,7 @@
 """
 
 import contextlib
+import sys
 
 from PyQt6.QtCore import (
     Q_ARG,
@@ -191,11 +192,18 @@
         messageType = "Fatal Error"
     if isinstance(message, bytes):
         message = message.decode()
-    print(
-        "{0}: {1} in {2} at line {3} ({4})".format(
-            messageType, message, context.file, context.line, context.function
-        )
+    output = "{0}: {1} in {2} at line {3} ({4})".format(
+        messageType, message, context.file, context.line, context.function
     )
+    try:
+        print(output)
+    except RuntimeError:
+        # The wrapped redirector object might be gone. Write an error message
+        # to the original stdout channel.
+        # Note: This can happen during shutdown of an applicaton.
+        if sys.__stdout__ is not None:
+            sys.__stdout__.write(output)
+            sys.__stdout__.flush()
 
 
 def qtHandler(minSeverity):

eric ide

mercurial