def _terminate_process(process, wait=2.5, kill=2.5):
"""Ensures that `process` terminates.
:return: The exit code of the process.
"""
try:
# The subprocess may have already been signalled, for example as part
# of this process's process group when Ctrl-c is pressed at the
# terminal, so give it some time to exit.
return process.wait(timeout=wait)
except subprocess.TimeoutExpired:
# Either the subprocess has not been signalled, or it's slow.
process.terminate() # SIGTERM.
try:
return process.wait(timeout=kill)
except subprocess.TimeoutExpired:
process.kill() # SIGKILL.
return process.wait()
评论列表
文章目录