Home > Backend Development > Python Tutorial > How to make a program run repeatedly in python

How to make a program run repeatedly in python

coldplay.xixi
Release: 2020-08-11 14:25:22
Original
17810 people have browsed it

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 .

How to make a program run repeatedly in python

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)
Copy after login

Method 2:

Repeat this .py Contents in the file

os.execvp(sys.executable, [sys.executable]+sys.argv)
Copy after login

or

python = sys.executable  # 获取当前执行python
 os.execl(python, python, *sys.argv)  # 执行命令
Copy after login

Method three:

Exception call function itself

def restart():
     try:
         fun()
     except EOFError as e:
         print(e)
     finally:
         restart()
Copy after login

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!

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template