Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

How to run python script until it ends without errors?

I have a following question. I have a script my_script.py. I would like to run it again, until it ends without errors. I run my_script.py from master.py like this:

import my_script

if __name__ == '__main__':
    my_script.main()

I tried:

if __name__ == '__main__':
  while True:
    try:
        my_script.main()
    except:
        pass

but this never ends. How can I end master.py when my_script.py ends succesfully ?

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

>Solution :

You can just set a flag or break to see if you finished or not, e.g.:

if __name__ == '__main__':
  while True:
    try:
        my_script.main()
        break
    except:
        pass
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading