Renamed delpid to term to better match its modified behavior. Moved the registration of the SIGTERM handler to avoid an extremely unlikely race condition.
This commit is contained in:
parent
6c78049886
commit
062131a10e
1 changed files with 5 additions and 4 deletions
|
|
@ -53,13 +53,14 @@ class Daemon:
|
|||
os.dup2(se.fileno(), sys.stderr.fileno())
|
||||
|
||||
# write pidfile
|
||||
signal.signal(signal.SIGTERM,self.delpid)
|
||||
|
||||
pid = str(os.getpid())
|
||||
with open(self.pidfile,'w+') as f:
|
||||
f.write(pid + '\n')
|
||||
|
||||
def delpid(self, _signo, _stack_frame):
|
||||
|
||||
# register listener for SIGTERM
|
||||
signal.signal(signal.SIGTERM, self.term)
|
||||
|
||||
def term(self, _signo, _stack_frame):
|
||||
os.remove(self.pidfile)
|
||||
sys.exit(0)
|
||||
|
||||
|
|
|
|||
Loading…
Reference in a new issue