From 177998f6a3d8b87a8c37a09249ca32904315fb67 Mon Sep 17 00:00:00 2001 From: Kovid Goyal Date: Sun, 24 Aug 2014 00:51:02 +0530 Subject: [PATCH] Possible fix for --detach crash on some linux systems Do not use file objects for redirecting the std streams as they could be garbage collected closing the streams. Also redirect stdin. I dont really expect either of these to fix the issue, but it's a start. --- src/calibre/gui2/__init__.py | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/src/calibre/gui2/__init__.py b/src/calibre/gui2/__init__.py index d4d8227f7a..be2d7c1890 100644 --- a/src/calibre/gui2/__init__.py +++ b/src/calibre/gui2/__init__.py @@ -880,9 +880,10 @@ def detach_gui(): if os.fork() != 0: raise SystemExit(0) os.setsid() - so, se = file(os.devnull, 'a+'), file(os.devnull, 'a+', 0) - os.dup2(so.fileno(), sys.__stdout__.fileno()) - os.dup2(se.fileno(), sys.__stderr__.fileno()) + si, so, se = os.open(os.devnull, os.O_RDONLY), os.open(os.devnull, os.O_WRONLY), os.open(os.devnull, os.O_WRONLY) + os.dup2(si, sys.__stdin__.fileno()) + os.dup2(so, sys.__stdout__.fileno()) + os.dup2(se, sys.__stderr__.fileno()) class Application(QApplication):