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,学会了为什么要使用装饰器,也明白了装饰器是什么了,但是你也许会问,是否可以在装饰器前面再添加一层装饰器,会怎么样呢?就像大楼一样,一层一层地叠在一起。其实是...

对Python Class之间函数的调用关系详解

假设有Class A 和 Class B两个类,Class A中定义了a(),Class B中定义了b(). 现在我想在Class B中调用 Class A中的函数a()。此处介绍三种调...

python处理按钮消息的实例详解

python处理按钮消息的实例详解

python处理按钮消息的实例详解            最新学习Python的基础知...

使用python实现ftp的文件读写方法

ftp登陆连接 from ftplib import FTP #加载ftp模块 ftp=FTP() #设置变量 ftp.set_debuglevel...

Python实现读取字符串按列分配后按行输出示例

本文实例讲述了Python实现读取字符串按列分配后按行输出。分享给大家供大家参考,具体如下: 问题: 输入一个字符串和一个数字,数字代表分为几行,需要按照给定的列存储方法存储下来之后按行...