python定时检查启动某个exe程序适合检测exe是否挂了

yipeiwu_com6年前Python基础
详见代码如下:
复制代码 代码如下:

import threading
import time
import os
import subprocess
def get_process_count(imagename):
p = os.popen('tasklist /FI "IMAGENAME eq %s"' % imagename)
return p.read().count(imagename)
def timer_start():
t = threading.Timer(120,watch_func,("is running..."))
t.start()
def watch_func(msg):
print "I'm watch_func,",msg
if get_process_count('main.exe') == 0 :
print subprocess.Popen([r'D:\shuaji\bin\main.exe'])
timer_start()
if __name__ == "__main__":
timer_start()
while True:
time.sleep(1)

相关文章

用python实现英文字母和相应序数转换的方法

第一步:字母转数字 英文字母转对应数字相对简单,可以在命令行输入一行需要转换的英文字母,然后对每一个字母在整个字母表中匹配,并返回相应的位数,然后累加这些位数即可。过程中,为了使结果更...

python按照多个条件排序的方法

对tuple进行排序,先按照第一个元素升序,如果第一个元素相同,再按照第二个元素降序排列。 L = [(12, 12), (34, 13), (32, 15), (12, 24),...

python代码 输入数字使其反向输出的方法

如下所示: # 输入数字使其反向输出 num = int(input("请输入一个数:")) i = 0 num1 = num while True: if num1...

python 寻找优化使成本函数最小的最优解的方法

今天来学习变量优化问题。寻找使成本函数最小的题解。适用于题解相互独立的情况,设计随机优化算法、爬山法、模拟退火算法、遗传算法。 优化问题的的精髓是:1、将题解转化为数字序列化,可以写出题...

Python第三方库face_recognition在windows上的安装过程

实际上face_recognition这个项目尤其是dlib更适用于Linux系统。经过我的测试,在性能方面,编译同样规格的项目,这个工具在Windows 10 上大约是Ubuntu上的...