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.
This commit is contained in:
Kovid Goyal 2022-08-29 04:58:24 +05:30
parent 4a6165bc42
commit 4dbdea4122
No known key found for this signature in database
GPG Key ID: 06BC317B515ACE7C

View File

@ -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'(?<!\r)\n', b'\r\n', raw)