Run system commands or call a sub-process and assign the return value to a variable. This makes it easy to pass the error up to your processes parent.

#!/usr/bin/env python
import sys
import subprocess as p
retval = p.call('touch file', shell=True, stdin=p.PIPE, stdout=p.PIPE)
if retval != 0:
exit(retval)
else:
print("no fail")