Skip to contentSkip to conversation

server/process/daemonize: Use sys.exit(), not os._exit() for server

PATCH Richard Purdie 1 participant 1 message Aug 24, 2020 1 message not in the archive

lore
Share & tools
lore

A message that is not in the archive (sent off-list or not yet received): [email protected]

#1 lore raw
Quoted 32 lines · Richard Purdie via lists.openembedded.org

By using os._exit() in the server, we confuse python programmers no end since atexit calls, along with threading cleanup calls are skipped. We're careful about the environment the server is created within so we should be able to use sys.exit() here and have things behave as the python devs intend.

---
 lib/bb/daemonize.py      | 4 +---
 lib/bb/server/process.py | 1 +
 2 files changed, 2 insertions(+), 3 deletions(-)
lib/bb/daemonize.py +1 -3
index f01e6ec7cc..0ec5ef3986 100644
@@ -89,9 +89,7 @@ def createDaemon(function, logfile):
         traceback.print_exc()
     finally:
         bb.event.print_ui_queue()
-        # os._exit() doesn't flush open files like os.exit() does. Manually flush
-        # stdout and stderr so that any logging output will be seen, particularly
+        # Manually flush stdout and stderr so that any logging output will be seen, particularly
         # exception tracebacks.
         sys.stdout.flush()
         sys.stderr.flush()
-        os._exit(0)
lib/bb/server/process.py +0 -0
index 65e1eab527..b03d64391b 100644

lib/bb/server/process.py class BitBakeServer(object): · line 498

Quoted 7 lines
lib/bb/server/process.py +1 -0
@@ -492,6 +492,7 @@ class BitBakeServer(object):
             # Flush any ,essages/errors to the logfile before exit
             sys.stdout.flush()
             sys.stderr.flush()
+        sys.exit(0)
 
 def connectProcessServer(sockname, featureset):
     # Connect to socket

For the archives, we can't merge this since it allows SystemExit to be seen in the parent process, e.g. the selftests when under unittest.

Cheers,

Richard