From 4dbdea412207d6a9f49875f66ea04c867468bb0c Mon Sep 17 00:00:00 2001 From: Kovid Goyal Date: Mon, 29 Aug 2022 04:58:24 +0530 Subject: [PATCH] close stdout/err handles before opening debug log There is an unconfirmed report about file in use errors, most likely the handles are inherited by some other process or an antivirus or whatever, but lets at least close them in the under our control. Windows is such a pain. --- src/calibre/gui2/main.py | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/calibre/gui2/main.py b/src/calibre/gui2/main.py index 8e7b7396df..ad5bf14ab4 100644 --- a/src/calibre/gui2/main.py +++ b/src/calibre/gui2/main.py @@ -434,6 +434,8 @@ def run_gui_(opts, args, app, gui_debug=None): debugfile = runner.main.gui_debug from calibre.gui2 import open_local_file if iswindows: + # detach the stdout/stderr/stdin handles + winutil.prepare_for_restart() with open(debugfile, 'r+b') as f: raw = f.read() raw = re.sub(b'(?