现在有一个程序,除非 Ctrl + C 否则不会停止,我需要一个 Python 程序去跑这个程序(需要跑的这个程序时 Go 写的)
主要代码是
cmd = '%s --config %s ' % (CORE_PROG, CONFIG_FILE_NAME)
try:
proc = subprocess.Popen(shlex.split(cmd), stdout=subprocess.PIPE, stderr=subprocess.PIPE)
output = json.loads(proc.communicate()[0]) # return the command output
if proc.returncode != 0:
raise Exception('Testing Fail: ' + str(output))
sleep(20)
# Should somehow stop the proc
尝试了很多办法, proc.kill(), proc.terminate(), proc.send_signal(signal.SIGTERM) 都不行