Skip to contentSkip to conversation

daemonize: Ensure child process exits safely

PATCH New Richard Purdie 1 participant 1 message Jul 31, 2017

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 daemonize: Ensure child process exits safely

When we create the child, if an exception occurred it was transfering back into the parent context. We don't want to do that us use a try/finally to ensure we exit.

We need to ensure a traceback is printed and any queued UI messages which may not have made it to the client UI at this point.

---
 lib/bb/daemonize.py | 11 ++++++++---
 1 file changed, 8 insertions(+), 3 deletions(-)
lib/bb/daemonize.py +8 -3
index 8380828..a4664ad 100644
@@ -30,6 +30,7 @@ __version__ = "0.2"
 import os                    # Miscellaneous OS interfaces.
 import sys                   # System-specific parameters and functions.
 import io
+import traceback
 
 # Default daemon parameters.
 # File mode creation mask of the daemon.
@@ -192,6 +193,10 @@ def createDaemon(function, logfile):
         sys.stdout = open(logfile, 'a+')
         sys.stderr = sys.stdout
 
-    function()
-
-    os._exit(0)
+    try:
+        function()
+    except Exception as e:
+        traceback.print_exc()
+        bb.event.print_ui_queue()
+    finally:
+        os._exit(0)
Signature · 1 line
2.7.4