在我的 Jupyter 笔记本中,我想执行一些长时间运行的后台作业并在单元格中显示它们的状态。我想,在做一些困难的事情之前,我可以先从一个时钟开始。
我在一个单元格中有以下代码
import ipywidgets as widgets
import time
from datetime import datetime as dt
from IPython.display import HTML
from IPython.display import display
import threading
out = widgets.Output()
@out.capture(clear_output=True, wait=True)
def display_time():
now = dt.now().strftime("%H:%M:%S")
display(HTML(f"""<h1><center>{now}</center></h1>"""))
def run_time():
while True:
time.sleep(1)
display_time()
out
当我调用 run_time()
时,我每秒更新一次时间,但我的笔记本阻塞在这个单元格上。所以我尝试了 threading.Thread(target=run_time).start()
但这不知何故只会在我与笔记本进行交互时更新时间。即使不进行任何单元格交互,如何更新笔记本?
最佳答案
您想查看 ipyrallel
以在您的笔记本中运行多内核。
这是一个solved issue
这是 documentation
https://stackoverflow.com/questions/57389808/
相关文章:
apache-spark - 将数据从 Spark Structured Streaming 加载到
javascript - ag-grid:根据rowNode内容在fullRow编辑和单个单元格编辑
python - Pygame display init on headless Raspberry
pandas - future 警告 : Passing datetime64-dtype data
swift - Swift 中 MSAL 和 AD B2C 的登录问题
react-native - 异步/等待函数返回 _40 : 0, _65 : 0, _55 : n
python - Google Sheets API 在本地工作,但从 AWS Lambda 运行时