Bail out of loop if python error occurs