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实现读取json文件到excel表

本文实例为大家分享了Python实现读取json文件到excel表,供大家参考,具体内容如下 一、需求 1、'score.json' 文件内容: { "1":["小花",99,1...

用Python编写一个高效的端口扫描器的方法

用Python编写一个高效的端口扫描器的方法

PyPortScanner python多线程端口扫描器。 输出示例: Github 此端口扫描器的源码,文档及详细调用方法见Github PythonPortScanner by...

python实现输出一个序列的所有子序列示例

python实现输出一个序列的所有子序列示例

如下所示: def sub(arr): finish=[] size = len(arr) end = 1 << size #end=2**size for in...

python验证码识别实例代码

本文研究的主要是Python验证码识别的相关代码,具体如下。 Talk is cheap, show you the Code! import numpy as np import...

详解Python的Twisted框架中reactor事件管理器的用法

详解Python的Twisted框架中reactor事件管理器的用法

铺垫 在大量的实践中,似乎我们总是通过类似的方式来使用异步编程: 监听事件 事件发生执行对应的回调函数 回调完成(可能产生新的事件添加进监听队列) 回到1,监听事件...