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

yipeiwu_com6年前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程序设计有所帮助。

相关文章

点球小游戏python脚本

本文实例为大家分享了python点球小游戏的具体代码,供大家参考,具体内容如下 1.游戏要求: 设置球的方向:左中右三个方向,射门或者扑救动作,循环5次,直接输入方向。电脑随机挑选方...

在SAE上部署Python的Django框架的一些问题汇总

花了些工夫将碎片网部署到了SAE,中途遇到各类问题。感觉SAE看上去很美,实际上却并不是太成熟(至少python版如此)。 下面记录下我遇到的一些主要问题以及解决方法。 django版本...

Empty test suite.(PyCharm程序运行错误的解决方法)

Empty test suite.(PyCharm程序运行错误的解决方法)

运行程序test4_4.py时报错,Empty test suite. 查找资料发现原因: 默认情况下,PyCharm将检查以test开头的文件,它们是unittest.TestCas...

python 上下文管理器使用方法小结

上下文管理器最常用的是确保正确关闭文件, with open('/path/to/file', 'r') as f: f.read() with 语句的基本语法, with...

django rest framework vue 实现用户登录详解

django rest framework vue 实现用户登录详解

后端代码就不介绍了,可以参考 django rest framework 实现用户登录认证 这里介绍一下前端代码,和前后端的联调过程 在components下新建login.vue 文件...