How to make the program run repeatedly in Python: 1. After reporting an error, restart the [.py] file and continue execution; 2. Repeat the contents of this [.py] file; 3. Call the function itself abnormally .
Python method to make the program run repeatedly:
Method 1:
After reporting the error, restart the .py
file and continue executing
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)
Method 2:
Repeat this .py Contents in the file
os.execvp(sys.executable, [sys.executable]+sys.argv)
or
python = sys.executable # 获取当前执行python os.execl(python, python, *sys.argv) # 执行命令
Method three:
Exception call function itself
def restart(): try: fun() except EOFError as e: print(e) finally: restart()
Related learning Recommended: python video tutorial
The above is the detailed content of How to make a program run repeatedly in python. For more information, please follow other related articles on the PHP Chinese website!