mirror of
https://github.com/kovidgoyal/calibre.git
synced 2025-07-09 03:04:10 -04:00
Fix stdout/stderr redirection temp files not being deleted when restarting calibre from within calibre on windows
This commit is contained in:
parent
e161c5f090
commit
19d2d7ed9a
@ -323,6 +323,8 @@ def run_gui(opts, args, actions, listener, app, gui_debug=None):
|
||||
app = os.path.dirname(os.path.dirname(sys.frameworks_dir))
|
||||
subprocess.Popen('sleep 3s; open '+app, shell=True)
|
||||
else:
|
||||
if iswindows and hasattr(winutil, 'prepare_for_restart'):
|
||||
winutil.prepare_for_restart()
|
||||
subprocess.Popen([e] + sys.argv[1:])
|
||||
else:
|
||||
if iswindows:
|
||||
|
@ -815,6 +815,15 @@ winutil_internet_connected(PyObject *self, PyObject *args) {
|
||||
Py_RETURN_FALSE;
|
||||
}
|
||||
|
||||
static PyObject *
|
||||
winutil_prepare_for_restart(PyObject *self, PyObject *args) {
|
||||
FILE *f1 = NULL, *f2 = NULL;
|
||||
if (stdout != NULL) fclose(stdout);
|
||||
if (stderr != NULL) fclose(stderr);
|
||||
_wfreopen_s(&f1, L"NUL", L"a+t", stdout);
|
||||
_wfreopen_s(&f2, L"NUL", L"a+t", stderr);
|
||||
Py_RETURN_NONE;
|
||||
}
|
||||
|
||||
static PyObject *
|
||||
winutil_strftime(PyObject *self, PyObject *args)
|
||||
@ -978,6 +987,10 @@ be a unicode string. Returns unicode strings."
|
||||
"internet_connected()\n\nReturn True if there is an active internet connection"
|
||||
},
|
||||
|
||||
{"prepare_for_restart", winutil_prepare_for_restart, METH_VARARGS,
|
||||
"prepare_for_restart()\n\nRedirect output streams so that the child process does not lock the temp files"
|
||||
},
|
||||
|
||||
{NULL, NULL, 0, NULL}
|
||||
};
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user