【发布时间】:2022-09-26 07:09:26
【问题描述】:
基本上我要做的是如果满足条件,则取消当前单元格和所有后续单元格的执行。如果 exit() 停止了笔记本的执行,这就是这个想法(但它只会停止运行它的单元格的执行)
yes_and_no_list = [\'yes\', \'y\', \'no\', \'n\']
response = \'\'
while not response.lower() in yes_and_no_list:
response = input(\"Continue running notebook?\")
if response in yes_and_no_list[2:]:
print(\"Notebook execution aborted.\")
exit()
....所以我想知道是否有一段代码或笔记本魔术可以替换 \'exit()\' 并停止整个 Colab 笔记本的执行?
我已经尝试过对这个问题的回答: How to terminate current colab session from notebook cell
...但是如果我将 exit() 替换为 !kill $(ps aux | awk \'{print $2}\') 它似乎不会打印它上面的行,“Notebook execution aborted.\”,所以我对它的工作原理感到困惑。
标签: python python-3.x linux jupyter-notebook google-colaboratory