本文實(shí)例講述了python定時(shí)檢查某個(gè)進(jìn)程是否已經(jīng)關(guān)閉的方法。分享給大家供大家參考。具體如下:
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)希望本文所述對(duì)大家的Python程序設(shè)計(jì)有所幫助。
新聞熱點(diǎn)
疑難解答
圖片精選