python定时检查某个进程是否已经关闭的方法

yipeiwu_com5年前Python基础

本文实例讲述了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程序设计有所帮助。

相关文章

Linux下Pycharm、Anaconda环境配置及使用踩坑

Linux下Pycharm、Anaconda环境配置及使用踩坑

配置环境花了我一下午的时间,简单记录一下,希望能帮到一些新手。 1、下载PyCharm:https://www.jetbrains.com/pycharm/download/ 下载完成后...

Python程序设计入门(2)变量类型简介

通常来说,Python的变量/数据类型非常多,但是它是不需要用户指定的,因为有些是根据部份系统函数生成,另外一些是自动根据变量的值识别的,这些数据类型常量在class types定义,所...

Python实现短网址ShortUrl的Hash运算实例讲解

本文实例讲述了Python实现短网址ShortUrl的Hash运算方法。分享给大家供大家参考。具体如下: shorturl实现常见的做法都是将原始Url存储到数据库,由数据库返回一个对应...

在python的WEB框架Flask中使用多个配置文件的解决方法

有些框架本身就支持多配置文件,例如Ruby On Rails,nodejs下的expressjs。python下的Flask虽然本身支持配置文件管理, 但单纯使用from_object和...

pip install urllib2不能安装的解决方法

python35 urllib2 不能用 Could not find a version that satisfies the requirement urllib2 (from...