[英]How to wait until user close the process in python?
I want to create a program that init a new process and then wait until thhis process was killed by user or another program.我想创建一个程序来初始化一个新进程,然后等到这个进程被用户或另一个程序杀死。
But i cant understand why the process create by subprocess is finished after a fraction of time and not by the user closing the process.但我不明白为什么子进程创建的进程在一小部分时间后完成,而不是用户关闭进程。
import subprocess
import psutil
old_process = {p.pid for p in psutil.process_iter()}
calc_process = subprocess.Popen('C:\Windows\System32\calc')
new_process = {p.pid for p in psutil.process_iter()}
process = list(new_process - old_process)[0]
while psutil.pid_exists(process):
print('Process running')
print('Done')
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.