本文實例講述了python定時檢查某個進程是否已經關閉的方法。分享給大家供大家參考。具體如下:
import threadingimport timeimport osimport subprocessdef 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程序設計有所幫助。
新聞熱點
疑難解答