[SPARK-2627] fail check on non-zero status
[SPARK-2627] miscellaneous PEP 8 fixes

Mostly done using autopep8, plus some hand fixes.