Commits

Aleš Erjavec  committed 5a36b47 Draft

Fix invalid stdout/stderr streams on windows when running without a console.

  • Participants
  • Parent commits b47f313

Comments (0)

Files changed (1)

File Orange/OrangeCanvas/main.py

         return False
 
 
+def fix_win_pythonw_std_stream():
+    """
+    On windows when running without a console (using pythonw.exe) the
+    std[err|out] file descriptors are invalid and start throwing exceptions
+    when their buffer is flushed (`http://bugs.python.org/issue706263`_)
+
+    """
+    if sys.platform == "win32" and \
+            os.path.basename(sys.executable) == "pythonw.exe":
+        if sys.stdout.fileno() < 0:
+            sys.stdout = open(os.devnull, "wb")
+        if sys.stderr.fileno() < 0:
+            sys.stderr = open(os.devnull, "wb")
+
+
 def main(argv=None):
     if argv is None:
         argv = sys.argv[1:]
 
     logging.basicConfig(level=levels[options.log_level])
 
+    fix_win_pythonw_std_stream()
+
     log.info("Starting 'Orange Canvas' application.")
 
     qt_argv = ["orange-canvas"]