在我按下 ctrl+C 之前,spark-submit 不会退出

spark-submit is not exiting until I hit ctrl+C

我正在 运行使用 Hortonworks 虚拟机 运行 将此 spark 命令成功地激发 Scala 程序。但是一旦作业完成,它就不会退出 spark-submit 命令,直到我按下 ctrl+C。为什么?

spark-submit --class SimpleApp --master yarn-client --num-executors 3 --driver-memory 512m --executor-memory12m --executor-cores 1 target/scala-2.10/application_2.10-1.0.jar /user/root/decks/largedeck.txt 

这里是代码,我是运行ning.

/* SimpleApp.scala */
import org.apache.spark.SparkContext
import org.apache.spark.SparkContext._
import org.apache.spark.SparkConf

object SimpleApp {
  def main(args: Array[String]) {
    val logFile = "YOUR_SPARK_HOME/README.md" // Should be some file on your system
    val conf = new SparkConf().setAppName("Simple Application")
    val sc = new SparkContext(conf) 
    val cards = sc.textFile(args(0)).flatMap(_.split(" "))
    val cardCount = cards.count()
    println(cardCount)
  }
}

您必须在上下文中调用 stop() 才能干净地退出程序。

我在将文件写入 S3 时遇到了同样的问题。我使用 spark 2.0 版本,即使在添加 stop() 之后如果它不适合你。尝试以下设置

在 Spark 2.0 中你可以使用,

val spark = SparkSession.builder().master("local[*]").appName("App_name").getOrCreate()
spark.conf.set("spark.hadoop.mapred.output.committer.class","com.appsflyer.spark.DirectOutputCommitter")
spark.conf.set("mapreduce.fileoutputcommitter.marksuccessfuljobs", "false")