[Python] python定时检查某个进程是否已经关闭 →→→→→进入此内容的聊天室

来自 , 2020-11-29, 写在 Python, 查看 247 次.
URL http://www.code666.cn/view/51fd081f
  1. import threading
  2. import time
  3. import os
  4. import subprocess
  5.  
  6.  
  7. def get_process_count(imagename):
  8.     p = os.popen('tasklist /FI "IMAGENAME eq %s"' % imagename)
  9.     return p.read().count(imagename)
  10.  
  11. def timer_start():
  12.     t = threading.Timer(120,watch_func,("is running..."))
  13.     t.start()
  14.    
  15. def watch_func(msg):
  16.     print "I'm watch_func,",msg
  17.     if get_process_count('main.exe') == 0 :
  18.         print subprocess.Popen([r'D:\shuaji\bin\main.exe'])
  19.     timer_start()
  20.    
  21. if __name__ == "__main__":
  22.     timer_start()
  23.     while True:
  24.         time.sleep(1)
  25. #//python/6389

回复 "python定时检查某个进程是否已经关闭"

这儿你可以回复上面这条便签

captcha