comparison tests/killdaemons.py @ 49309:d54b213c4380

py3: catch ProcessLookupError instead of checking errno == ESRCH
author Manuel Jacob <me@manueljacob.de>
date Tue, 31 May 2022 23:45:33 +0200
parents 6000f5b25c9b
children 493034cc3265
comparison
equal deleted inserted replaced
49308:d2adebe35635 49309:d54b213c4380
1 #!/usr/bin/env python3 1 #!/usr/bin/env python3
2 2
3 import errno
4 import os 3 import os
5 import signal 4 import signal
6 import sys 5 import sys
7 import time 6 import time
8 7
91 else: 90 else:
92 time.sleep(0.1) 91 time.sleep(0.1)
93 os.kill(pid, 0) 92 os.kill(pid, 0)
94 logfn('# Daemon process %d is stuck - really killing it' % pid) 93 logfn('# Daemon process %d is stuck - really killing it' % pid)
95 os.kill(pid, signal.SIGKILL) 94 os.kill(pid, signal.SIGKILL)
96 except OSError as err: 95 except ProcessLookupError:
97 if err.errno != errno.ESRCH: 96 pass
98 raise
99 97
100 98
101 def killdaemons(pidfile, tryhard=True, remove=False, logfn=None): 99 def killdaemons(pidfile, tryhard=True, remove=False, logfn=None):
102 if not logfn: 100 if not logfn:
103 logfn = lambda s: s 101 logfn = lambda s: s