所以我制作了一个打开 Tor 浏览器的程序,我需要在一段时间后杀死该浏览器,我该怎么做
我尝试用 os.system 和 Linux 命令杀死它
这是我启动浏览器的命令
subprocess.call(['./start-tor-browser.desktop'])
最佳答案
查看 subprocess.call
的文档,它说:
Run the command described by args. Wait for command to complete, then return the
returncode
attribute.
subprocess.call
等待命令完成,即直到 Tor 在您的情况下关闭。相反,您可以使用较低级别的 Popen
API directly它可以让您在进程生成后控制该进程。
在这种情况下,您的代码最终将如下所示:
p = subprocess.Popen(['./start-tor-browser.desktop'])
# ...
# do other stuff here
p.kill()
关于python - 我怎样才能杀死我用 python 启动的进程,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/57897181/