def _wait_and_kill(self, killfun, proc, deferred, tries=0):
"""
Check if the process is still alive, and call the killfun
after waiting several times during a timeout period.
:param tries: counter of tries, used in recursion
:type tries: int
"""
if tries < TERMINATE_MAXTRIES:
if proc.transport.pid is None:
deferred.callback(True)
return
else:
self.log.debug('Process did not die, waiting...')
tries += 1
reactor.callLater(
TERMINATE_WAIT,
self._wait_and_kill, killfun, proc, deferred, tries)
return
# after running out of patience, we try a killProcess
d = killfun()
d.addCallback(lambda _: deferred.callback(True))
return d
评论列表
文章目录