简体   繁体   English

我可以在 Jupyter 笔记本中运行一个单元,而另一个单元正在运行吗?

[英]Can I run a cell in a Jupyter notebook while another cell is running?

As the title says, is there a way to run a Jupyter Notebook cell in the background (in Python)?正如标题所说,有没有办法在后台(在 Python 中)运行 Jupyter Notebook 单元?

For example, is there a hypothetical magic command %%run_in_background that allows me to kick off a cell to execute in the background without blocking other cells from executing.例如,是否有一个假设的魔术命令%%run_in_background允许我启动一个单元格以在后台执行而不会阻止其他单元格执行。

Technically you can't do that, each kernel is like an instance of python, you can only run a script at a time.从技术上讲你不能这样做,每个 kernel 就像 python 的一个实例,你一次只能运行一个脚本。

You could run the cell, then refresh the browser and run the notebook fresh.您可以运行单元格,然后刷新浏览器并重新运行笔记本。 The previous command will continue running but there is no way of accessing it in the notebook anymore.上一个命令将继续运行,但无法再在笔记本中访问它。 You won't get the result you want, the output from the previous run won't appear in this new instance.你不会得到你想要的结果,之前运行的 output 不会出现在这个新实例中。

Your best bet is to use 2 different notebooks, or 2 python scripts or use multiprocessing modules.您最好的选择是使用 2 个不同的笔记本,或 2 个 python 脚本或使用多处理模块。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM