Python regularly checks whether a process has been shut down

From , 3 Years ago, written in Python, viewed 83 times.
URL https://pastebin.vip/view/c778a2d8
  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

Reply to "Python regularly checks whether a process has been shut down"

Here you can reply to the paste above

captcha

https://burned.cc - Burn After Reading Website