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获取某年中每个月的第一天和最后一天

搜索关键字: python get every first day of month 参考解答: 方法一: >>> import calendar >>...

Pytorch之保存读取模型实例

pytorch保存数据 pytorch保存数据的格式为.t7文件或者.pth文件,t7文件是沿用torch7中读取模型权重的方式。而pth文件是python中存储文件的常用格式。而在ke...

python3使用PyMysql连接mysql数据库实例

python语言的3.x完全不向前兼容,导致我们在python2.x中可以正常使用的库,到了python3就用不了了.比如说mysqldb 目前MySQLdb并不支持python3.x...

Python3安装Pillow与PIL的方法

关于Pillow与PIL PIL(Python Imaging Library)是Python一个强大方便的图像处理库,名气也比较大。不过只支持到Python 2.7。 PIL官方网站:...

50行代码实现贪吃蛇(具体思路及代码)

50行代码实现贪吃蛇(具体思路及代码)

最近一直在准备用来面试的几个小demo,为了能展现自己,所以都是亲自设计并实现的,其中一个就是在50行代码内来实现一个贪吃蛇,为了说明鄙人自己练习编程的一种方式--把代码写短,为了理解语...