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 将pdf转成图片的方法

Python 将pdf转成图片的方法

本篇文章记录如何使用python将pdf文件切分成一张一张图片,包括环境配置、版本兼容问题。 环境配置(mac) 安装ImageMagick brew install imagemagi...

django框架中ajax的使用及避开CSRF 验证的方式详解

django框架中ajax的使用及避开CSRF 验证的方式详解

本文实例讲述了django框架中ajax的使用及避开CSRF 验证的方式。分享给大家供大家参考,具体如下: ajax(Asynchronous Javascript And Xml) 异...

python读取文本中的坐标方法

利用python读取文本文件很方便,用到了string模块,下面用一个小例子演示读取文本中的坐标信息。 import string x , y , z = [] , [] ,[]...

巧用Python装饰器 免去调用父类构造函数的麻烦

先看一段代码: 复制代码 代码如下: class T1(threading.Thread): def __init__(self, a, b, c): super(T1, self)._...

利用numpy和pandas处理csv文件中的时间方法

利用numpy和pandas处理csv文件中的时间方法

环境:numpy,pandas,python3 在机器学习和深度学习的过程中,对于处理预测,回归问题,有时候变量是时间,需要进行合适的转换处理后才能进行学习分析,关于时间的变量如下所示,...