這篇文章將為大家詳細(xì)講解有關(guān)python讓程序重復(fù)運(yùn)行的方法,小編覺(jué)得挺實(shí)用的,因此分享給大家做個(gè)參考,希望大家閱讀完這篇文章后可以有所收獲。
python讓程序重復(fù)運(yùn)行的方法:1、報(bào)錯(cuò)后,重新啟動(dòng)【.py】文件,繼續(xù)執(zhí)行;2、重復(fù)執(zhí)行本【.py】文件中的內(nèi)容;3、異常調(diào)用函數(shù)本身。
python讓程序重復(fù)運(yùn)行的方法:
方法一:
報(bào)錯(cuò)后,重新啟動(dòng).py
文件,繼續(xù)執(zhí)行
while 1: run_ticker = 'python ticker.py' run_depth = 'python depth.py' run_depth_pct = 'python depth_pct.py' run_trade = 'python trade.py' os.system(run_depth_pct)
方法二:
重復(fù)執(zhí)行本.py文件中的內(nèi)容
os.execvp(sys.executable, [sys.executable]+sys.argv)
或
python = sys.executable # 獲取當(dāng)前執(zhí)行python os.execl(python, python, *sys.argv) # 執(zhí)行命令
方法三:
異常調(diào)用函數(shù)本身
def restart(): try: fun() except EOFError as e: print(e) finally: restart()
關(guān)于python讓程序重復(fù)運(yùn)行的方法就分享到這里了,希望以上內(nèi)容可以對(duì)大家有一定的幫助,可以學(xué)到更多知識(shí)。如果覺(jué)得文章不錯(cuò),可以把它分享出去讓更多的人看到。