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

软件发布|下载排行|最新软件

当前位置:首页IT学院IT技术

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

lele   2021-03-21 我要评论
想了解python定时检查某个进程是否已经关闭的方法的相关内容吗,lele在本文为您仔细讲解python定时检查某个进程是否已经关闭的相关知识和一些Code实例,欢迎阅读和指正,我们先划重点: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程序设计有所帮助。

猜您喜欢

Copyright 2022 版权所有 软件发布 访问手机版

声明:所有软件和文章来自软件开发商或者作者 如有异议 请与本站联系 联系我们