psutil 检测exe是否已经运行
安装依赖
pip install psutil
代码
import psutil
def check_if_process_running(process_name):
'''
Check if there is any running process that contains the given name process_name.
'''
# Iterate over the all the running process
for proc in psutil.process_iter():
try:
# Check if process name contains the given name string.
if process_name.lower() in proc.name().lower():
return True
except (psutil.NoSuchProcess, psutil.AccessDenied, psutil.ZombieProcess):
pass
return False;
# Check if "example.exe" process is running
is_running = check_if_process_running('xxx.exe')
print('xxx.exe is running: ' + str(is_running))
作者:人间春风意
扫描左侧的二维码可以赞赏

本作品采用署名-非商业性使用-禁止演绎 4.0 国际 进行许可。

浙公网安备 33010602011771号