我有一个python脚本,它永久地发送数据,在看到它的输出后,我想停止或杀死python脚本.in lettuce,我不能设法杀死python script.Any,对此有什么想法?我试过了:
os.system('pgrep -f sample.py')
time.sleep(3.0)
os.system('pkill -9 -f sample.py')发布于 2018-04-16 15:50:32
Try子过程,它更加干净和优雅。在执行命令后,可以通过p.communicate()读取命令输出。
p = subprocess.Popen(['pgrep', '-f', 'sample.py'], stdout=subprocess.PIPE, stderr=subprocess.PIPE)
pid = p
time.sleep(3.0)
os.kill(pid=pid, sig=9)https://stackoverflow.com/questions/49851913
复制相似问题