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)

相关文章

tensorflow 获取模型所有参数总和数量的方法

实例如下所示: from functools import reduce from operator import mul def get_num_params(): num_p...

关于python导入模块import与常见的模块详解

0.什么是python模块?干什么的用的? Java中如果使用abs()函数,则需要需要导入Math包,同样python也是封装的,因为python提供的函数太多,所以根据函数的功能将其...

从Python程序中访问Java类的简单示例

from jnius import autoclass >>> Stack = autoclass('java.util.Stack') >>>...

python中in在list和dict中查找效率的对比分析

首先给一个简单的例子,测测list和dict查找的时间: import time query_lst = [-60000,-6000,-600,-60,-6,0,6,60,600,6...

python定时利用QQ邮件发送天气预报的实例

python定时利用QQ邮件发送天气预报的实例

大致介绍 好久没有写博客了,正好今天有时间把前几天写的利用python定时发送QQ邮件记录一下 1、首先利用request库去请求数据,天气预报使用的是和风天气的API(www.hewe...