Fix stdout/stderr redirection temp files not being deleted when restarting calibre from within calibre on windows

This commit is contained in:
Kovid Goyal 2013-02-16 10:36:03 +05:30
parent e161c5f090
commit 19d2d7ed9a
2 changed files with 15 additions and 0 deletions

View File

@ -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)) app = os.path.dirname(os.path.dirname(sys.frameworks_dir))
subprocess.Popen('sleep 3s; open '+app, shell=True) subprocess.Popen('sleep 3s; open '+app, shell=True)
else: else:
if iswindows and hasattr(winutil, 'prepare_for_restart'):
winutil.prepare_for_restart()
subprocess.Popen([e] + sys.argv[1:]) subprocess.Popen([e] + sys.argv[1:])
else: else:
if iswindows: if iswindows:

View File

@ -815,6 +815,15 @@ winutil_internet_connected(PyObject *self, PyObject *args) {
Py_RETURN_FALSE; 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 * static PyObject *
winutil_strftime(PyObject *self, PyObject *args) 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" "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} {NULL, NULL, 0, NULL}
}; };