Skip to content

Commit

Permalink
SessionBasedDaemon: register atexit() handlers *after* forking.
Browse files Browse the repository at this point in the history
  • Loading branch information
riccardomurri committed Apr 10, 2018
1 parent c8488e5 commit 0ce8fe2
Showing 1 changed file with 5 additions and 2 deletions.
7 changes: 5 additions & 2 deletions gc3libs/cmdline.py
Expand Up @@ -2488,8 +2488,6 @@ def _main(self):
" Ensure no other daemon is running,"
" then delete file and re-run this command."
.format(lockfile_path))
# ensure PID file is removed upon termination
atexit.register(rm_f, lockfile_path)

if self.params.foreground:
context = lockfile
Expand All @@ -2514,6 +2512,11 @@ def _main(self):
self.log.info("About to daemonize ...")

with context:
# ensure PID file is removed upon termination -- we need
# to do this *after* forking to avoid the PID file being
# prematurely removed while the daemon is still
# preparing...
atexit.register(rm_f, lockfile_path)
self._start_inboxes()
self._start_server()
self.running = True
Expand Down

0 comments on commit 0ce8fe2

Please sign in to comment.