From 1d81becdefabf6bf67c3f78e3129b82c64932a1d Mon Sep 17 00:00:00 2001 From: Alexander Richards Date: Mon, 9 Dec 2019 10:49:13 +0000 Subject: [PATCH] Update daemon PID before parent exits This commit will have the parent process write the daemon PID before it exits. This ensures that immediately after parent exits a valid PID is available from the pid file. --- daemonize.py | 2 ++ 1 file changed, 2 insertions(+) diff --git a/daemonize.py b/daemonize.py index 2585b09..d17b9a5 100644 --- a/daemonize.py +++ b/daemonize.py @@ -106,6 +106,8 @@ def start(self): self.logger.error("Unable to fork, errno: {0}".format(e.errno)) sys.exit(1) if process_id != 0: + with open(self.pid, "w") as pidfile: + pidfile.write(str(process_id)) if self.keep_fds: # This is the parent process. Exit without cleanup, # see https://github.com/thesharp/daemonize/issues/46