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)

相关文章

Python3+PyInstall+Sciter解决报错缺少dll、html等文件问题

Python3+PyInstall+Sciter解决报错缺少dll、html等文件问题

1 调试过程 用Python3.6+Sciter+PyCharm写了一个py测试脚本helloworld.py,该脚本中只含有一条语句“import sciter”。在PyCharm中运...

python操作ie登陆土豆网的方法

本文实例讲述了python操作ie登陆土豆网的方法。分享给大家供大家参考。具体如下: 这里利用ie操作登陆土豆网,很简单,仅做一下记录,以备后用。 # -*- coding: utf...

python里使用正则表达式的组嵌套实例详解

python里使用正则表达式的组嵌套实例详解 由于组本身是一个完整的正则表达式,所以可以将组嵌套在其他组中,以构建更复杂的表达式。下面的例子,就是进行组嵌套的例子: #python...

pandas通过loc生成新的列方法

pandas通过loc生成新的列方法

pandas中一个很便捷的使用方法通过loc、iloc、ix等索引方式,这里记录一下: df.loc[条件,新增列] = 赋初始值 如果新增列名为已有列名,则在原来的数据列上改变 i...

python matplotlib中文显示参数设置解析

python matplotlib中文显示参数设置解析

最近在学习python著名的绘图包matplotlib时发现,有时候图例等设置无法正常显示中文,于是就想把这个问题解决了。 PS:本文仅针对Windows,其他平台仅供参考。 原因 大致...