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)

相关文章

Python ORM框架SQLAlchemy学习笔记之数据查询实例

前期我们做了充足的准备工作,现在该是关键内容之一查询了,当然前面的文章中或多或少的穿插了些有关查询的东西,比如一个查询(Query)对象就是通过Session会话的query()方法获取...

Linux下为不同版本python安装第三方库

问题背景 目前的linux发行版上,有很多安装了两个版本的python。 我的机器上默认的版本为python 2.x。且在使用easy_install安装第三方库时,也默认安装到了2...

python中的TCP(传输控制协议)用法实例分析

本文实例讲述了python中的TCP(传输控制协议)用法。分享给大家供大家参考,具体如下: 1.TCP与UDP的不同: windows网络调试助手下载:https://pan.baidu...

Python脚本实现虾米网签到功能

Python脚本实现虾米网签到功能

本文实例讲述了Python脚本实现虾米网签到功能的方法。分享给大家供大家参考,具体如下: 概述 这个脚本完成了自动登录虾米网、签到的功能。 大致要用到urllib、urllib2、coo...

在dataframe两列日期相减并且得到具体的月数实例

如下所示: df = pd.DataFrame(np.random.randn(6,4), index=pd.date_range('20130101', periods=6), c...