【问题标题】:Stop Execution of Databricks notebook after specific cell在特定单元格后停止执行 Databricks 笔记本
【发布时间】:2021-05-22 07:35:53
【问题描述】:

我在 Databricks 笔记本上尝试了 sys.exit(0)(Python 代码)和 dbutils.notebook.exit()。但是这两个选项都不起作用。 请提出任何其他方法来停止在 Databricks 笔记本中的特定单元格之后执行代码。

【问题讨论】:

  • 引发异常?
  • @AlexOtt 我已经尝试过了,但这也行不通。尝试: if(df.shape[0]==0 and df_1.shape[0]==0 and df_2.shape[0]==0): print('Stop the excution here') dbutils.notebook.exit( 'stop') else: pass except: print('ex')
  • dbuilts.notebook.exit() 在从另一个笔记本调用笔记本时使用,而不是在交互执行时使用。只需使用raise Exception("exit") 代替它...
  • @AlexOtt 你能提供代码吗?这会很有帮助。
  • 我写的 - 它只是有raise

标签: azure-databricks


【解决方案1】:

dbutils.notebook.exit() 不起作用,因为您需要输入字符串参数,没有它它会静默失败。为了让它工作,你应该写这样的东西:

dbutils.notebook.exit("whatever reason to make it stop")

【讨论】:

  • 虽然另一个答案确实显示了.exit() 的使用,但这个答案补充说,如果您不传递字符串参数,调用将静默失败。也许这个答案可能是对另一个答案的评论。
【解决方案2】:

就用这个吧。然后单击 Databricks 笔记本上的运行所有单元格按钮。如果满足条件,则停止执行。为我工作。

if (df.shape[0]==0): dbutils.notebook.exit('stop')

【讨论】:

    猜你喜欢
    • 2022-09-26
    • 2020-12-21
    • 1970-01-01
    • 1970-01-01
    • 2023-03-24
    • 2022-08-09
    • 1970-01-01
    • 1970-01-01
    • 2023-03-18
    相关资源
    最近更新 更多