This article recommend using “return” to jump out of a PySpark application. But after I did by following what he said. It reports error:

  File "", line 333
SyntaxError: 'return' outside function

Seems it can’t work. After trying to run PySpark application on my own laptop, I finally got the correct answer:

import sys
if df.rdd.isEmpty():