[英]How to open a subprocess (within a python script) in new terminal and kill it after 15 seconds (Platform: Ubuntu)
I am trying to start a subprocess in a new window from a python script file - timeout for 15 seconds then terminate that process without closing the main terminal window.我正在尝试从 python 脚本文件的新 window 中启动一个子进程 - 超时 15 秒然后终止该进程而不关闭主终端 window。
this is what I have so far...这是我到目前为止...
cmd=subprocess.Popen('file_name.sh')
subprocess.Popen('gnome terminal -c cmd')
time.sleep(15)
Popen.terminate(cmd)
Try this:尝试这个:
import subprocess
import time
proc = subprocess.Popen(('gnome-terminal', '--', 'file_name.sh'))
time.sleep(15)
subprocess.Popen(('pkill', '-f', 'file_name.sh'))
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.