I recommend changing your error handling code to raise some sort of exception instead of printing an error message and exiting. This will allow other code to catch the exception and handle the error in an appropriate manner.