简体   繁体   中英

Automatically restart Python script in Windows

I wrote a Python script to use Twitter Stream API. Sometime error occurs and it stops streaming.

What can I do to make the script restart automatically? Is it something about bash?

I am not using Linux. Appreciate any solution for Windows. Thank you.

You can either:

  • Use loop to run your script:

Bash:

while true; do ./your_script.py; done

Windows CMD:

:loop

./your_script.py

goto loop
  • Add a try/except to your main function and add a loop there:
def main():
    while True:
        try:
            your_logic()
        except:
            pass

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM