怎么判定python能不能运行_如何检查进程是否在Python中运行?

如果您坚持不使用第三方模块(我认为在Windows上运行的win32api无论如何都应该与Python一起提供),那么您至少可以将大部分工作转移到使用win32api而不是试图通过Python完成所有事情的系统上。我是这样做的:import subprocess

import time

# list of processes to auto-kill

kill_list = ["chrome.exe", "opera.exe", "iexplore.exe", "firefox.exe"]

# WMI command to search & destroy the processes

wmi_command = "wmic process where \"{}\" delete\r\n".format(

" OR ".join("Name='{}'".format(e) for e in kill_list))

# run a single subprocess with Windows Command Prompt

proc = subprocess.Popen(["cmd.exe"], stdout=subprocess.PIPE, stdin=subprocess.PIPE)

while True:

proc.stdin.write(wmi_command.encode("ascii")) # issue the WMI command to it

proc.stdin.flush() # flush the STDIN buffer

time.sleep(1) # let it breathe a little

在大多数情况下,您甚至不会注意到这一点对性能的影响。在

现在,为什么你需要这样的东西首先是一个完全不同的话题-我认为这样的脚本在现实世界中是没有用处的。在

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值