通过执行以下操作,我可以从另一个笔记本运行一个笔记本:
#calling_notebook.ipynb
get_ipython().run_line_magic('run', 'called_notebook.ipynb')
在我的用例中,我可以从被调用的笔记本中获取与Http相关的异常,而这些异常通常只是通过重新运行笔记本而消失。因此,我想从calling_notebook捕获这些异常并重新运行。像这样:
#calling_notebook.ipynb
import time
from selenium.common.exceptions import WebDriverException, TimeoutException
from http.client import RemoteDisconnected
try:
get_ipython().run_line_magic('run', 'called_notebook.ipynb')
except (WebDriverException, TimeoutException, RemoteDisconnected):
time.sleep(60)
get_ipython().run_line_magic('run', 'called_notebook.ipynb')
您做了这样的事情吗?