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

yipeiwu_com5年前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 用lambda函数替换for循环的方法

场景如下: 现在有一个dataframe,其中一列为score,值从0-100, df: score 98 88 37 68 86 33 现在需要增加一列level,给这些分数分类,90...

python函数的5种参数详解

(1)       位置参数,调用函数时按位置传入参数 (2)     &n...

Python中实现单例模式的n种方式和原理

在Python中如何实现单例模式?这可以说是一个经典的Python面试题了。这回我们讲讲实现Python中实现单例模式的n种方式,和它的原理。 什么是单例模式 维基百科 中说: 单例模式...

python re模块的高级用法详解

python re模块的高级用法详解

总结 以上所述是小编给大家介绍的python re模块的高级用法详解,希望对大家有所帮助,如果大家有任何疑问请给我留言,小编会及时回复大家的。在此也非常感谢大家对【听图阁-专注于P...

Python作用域用法实例详解

本文实例分析了Python作用域用法。分享给大家供大家参考,具体如下: 每一个编程语言都有变量的作用域的概念,Python也不例外,以下是Python作用域的代码演示: def sc...