如何判断 IPython 是否正在运行?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/32319410/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
How can I tell if IPython is running?
提问by Richard
I have an IPython notebook. I have a long-running loop that produces no output in one of the code blocks. It's not this, but imagine it was this:
我有一个 IPython 笔记本。我有一个长时间运行的循环,在其中一个代码块中不产生任何输出。不是这个,但想象一下是这样的:
for i in range(100):
time.sleep(2)
I started the code block running a while ago, and now I can't tell whether it's finished, or whether it's still running.
前段时间开始运行代码块,现在不知道是完成了,还是还在运行。
All the IPython status bar says at the top is Last Checkpoint: 23 minutes ago (autosaved)
. There's nothing in the browser tab to show whether it's running code, either.
所有 IPython 状态栏在顶部说的是Last Checkpoint: 23 minutes ago (autosaved)
. 浏览器选项卡中也没有任何内容可以显示它是否正在运行代码。
I don't want to start the next block because I don't know if this block has finished.
我不想开始下一个块,因为我不知道这个块是否已经完成。
And I don't want to stop the kernel and add print statements to this block, because if it's 80% of the way through, I don't want to kill it and restart it!
而且我不想停止内核并向这个块添加打印语句,因为如果它已经完成了 80%,我不想杀死它并重新启动它!
Is there anything in IPython - either the browser window or the console - that indicates what code is running right now?
IPython 中是否有任何内容(浏览器窗口或控制台)指示当前正在运行的代码?
回答by abc
The block of code will have the line number indicator like this ln[*]
, which means that the block is running:
代码块将有这样的行号指示符ln[*]
,这意味着该块正在运行:
Edit 1:
编辑1:
There is a bug in Jupyter notebooks and Jupyter lab (formerly known as Ipython notebooks) where refreshing or reopening the notebook will not keep the previous output (which includes ln[*]
): https://github.com/jupyter/jupyter/issues/83
Jupyter 笔记本和 Jupyter 实验室(以前称为 Ipython 笔记本)中存在一个错误,刷新或重新打开笔记本不会保留以前的输出(包括ln[*]
):https: //github.com/jupyter/jupyter/issues/83
Edit 2:
编辑2:
If you are willing to use a library to show if a cell is running (and its progress), I recommend tqdmto add progress bars:
如果您愿意使用库来显示单元格是否正在运行(及其进度),我建议使用tqdm添加进度条:
回答by f2003596
look to the right of ipython terminal, there is a circle. if the block is still running you would see a solid circle and when you hover it says "kernel busy"
看看 ipython 终端的右边,有一个圆圈。如果块仍在运行,您会看到一个实心圆圈,当您悬停时,它会显示“内核繁忙”
if there is nothing running, you would see an empty circle and when you hover it says "kernel idle"
如果没有任何东西在运行,你会看到一个空的圆圈,当你悬停时它会显示“内核空闲”
回答by Praveena
- You can see whether code still being executed or not in three places, In the top right corner, there will small circle which stays solid till the execution of code completes.
- 你可以在三个地方看到代码是否还在执行,在右上角,会有一个小圆圈,它会一直保持直到代码执行完成。
- Every cell will have cell number but when that cell being executed it will show
*
instead of a number
- 每个单元格都有单元格编号,但是当该单元格被执行时,它将显示
*
而不是数字
- In chrome and firefox browsers tabs icon changes from notebook to a clock.
- 在 chrome 和 firefox 浏览器中,标签图标从笔记本变为时钟。
回答by Umesh W
Also, in the browser tab (chrome in my case), you see the timer icon when a cell is executing. This is handy if you are in some other tab and want to check the execution status. timer image
此外,在浏览器选项卡(在我的情况下为 chrome)中,您会在单元格执行时看到计时器图标。如果您在其他选项卡中并想要检查执行状态,这将很方便。 定时器图像