python定時檢查某個進程是否已經(jīng)關閉的方法
更新時間:2015年05月20日 12:06:19 作者:lele
這篇文章主要介紹了python定時檢查某個進程是否已經(jīng)關閉的方法,涉及Python進程與時間的相關操作技巧,需要的朋友可以參考下
本文實例講述了python定時檢查某個進程是否已經(jīng)關閉的方法。分享給大家供大家參考。具體如下:
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程序設計有所幫助。
相關文章
windows下安裝Python虛擬環(huán)境virtualenvwrapper-win
這篇文章主要介紹了windows下安裝Python虛擬環(huán)境virtualenvwrapper-win,內(nèi)容超簡單,非常不錯,具有一定的參考借鑒價值,需要的朋友可以參考下2019-06-06
關于Pycharm配置翻譯插件Translation報錯更新TTK失敗不能使用的問題
這篇文章主要介紹了關于Pycharm配置翻譯插件Translation報錯更新TTK失敗不能使用的問題,本文通過圖文并茂的形式給大家分享解決方案,需要的朋友可以參考下2022-04-04

