You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

如何在spark-shell中停止Structured Streaming查询?

Spark Shell中Structured Streaming任务的正确终止方法
  • 两次按下Ctrl+C:第一次Ctrl+C会触发中断信号,但awaitTermination()的阻塞逻辑可能未立即响应,第二次按下会强制触发JVM退出,同时终止Streaming任务。
  • 通过应用ID手动终止:
    1. 登录Spark UI,在Applications标签页找到任务的应用ID(格式如application_1699999999_0001)
    2. 打开新终端,执行对应命令:
      • 本地/Standalone模式:
        ./bin/spark-class org.apache.spark.deploy.Client stop <你的应用ID>
        
      • YARN集群模式:
        yarn application -kill <你的应用ID>
        
  • 修改代码预留终止入口:
    启动任务时先保存StreamingQuery对象,通过手动输入触发停止,避免直接用awaitTermination()阻塞:
    val query = result.writeStream.outputMode("complete").format("console").start()
    scala.io.StdIn.readLine("按下回车键停止任务...")
    query.stop()
    query.awaitTermination()
    
    这样在Spark Shell中按下回车,就能优雅终止任务。

内容的提问来源于stack exchange,提问作者beatrice

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.08.07 12:10:20