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脚本

注意:Win7或者WIn8用户要用管理员权限执行。 项目地址:http://code.google.com/p/my-hosts-file/downloads复制代码 代码如下:impo...

python去掉字符串中重复字符的方法

复制代码 代码如下:If order does not matter, you can use "".join(set(foo))set() will create a set of u...

Python3.x对JSON的一些操作示例

前言 本文主要给大家介绍了关于python3对JSON的一些操作,分享出来供大家参考学习,下面话不多说了,来一起看看详细的介绍吧。 一、Dictionary 转为JSON 将dict转为...

Python cx_freeze打包工具处理问题思路及解决办法

以下是在使用cx_freeze过程中遇到的问题及解决办法(Win7) 1.问题描述:运行exe,启动无数个主程序,导致系统无法使用     原因:在程序中使用了multiprocess...

PyTorch中常用的激活函数的方法示例

PyTorch中常用的激活函数的方法示例

神经网络只是由两个或多个线性网络层叠加,并不能学到新的东西,简单地堆叠网络层,不经过非线性激活函数激活,学到的仍然是线性关系。 但是加入激活函数可以学到非线性的关系,就具有更强的能力去进...