How to handle non-generic errors in python?

Question:

I have a loop that I run via the statement:
os.system('python3 wrapper.py') which generates some files.

And every so often it hits an error such as this:

pybullet.error: Cannot load URDF file.
Error: InMemoryFile::~InMemoryFileIO (numAllocs 1 numFrees 2

This message is printed to the terminal. I would like to know how I can automatically get my code to start running again so long as the number of files generated is less than 20.

I tried the following:

while numberOfFilesGeneratedByLoop != 20:
     os.system('python3 wrapper.py')

However, it was still stopped by the same error.

Asked By: display_name_1

||

Answers:

python3 file.py > outputLog.txt

Log the output of your file to a .txt file, and then you can read through it. You can conditionally re-run your wrapper if the non-generic error statements are in outputLog.txt.

Answered By: FrustratedSnake
Categories: questions Tags: ,
Answers are sorted by their score. The answer accepted by the question owner as the best is marked with
at the top-right corner.