[英]How to automate running of Jupyter Notebook cells periodically
I want to integrate my jupyter notebook with my website, where I have written the code to fetch real-time data from MySQL
server and do real-time visualisation using plotly
. 我想将jupyter笔记本与我的网站集成在一起,在那儿我编写了从MySQL
服务器获取实时数据并使用plotly
进行实时可视化的plotly
。 But every time I'm having to run all the cells of my Kernel. 但是每次我必须运行内核的所有单元时。 Is there a way I can automate the running of the Jupyter notebook cells periodically say everyday 1 hour? 有什么方法可以使Jupyter笔记本电脑的电池定期自动运行,例如每天1小时?
My suggestion would be to 我的建议是
I can provide the commands here, but they are pretty straight forward and can easily be followed from the links. 我可以在此处提供命令,但是它们非常简单,可以从链接中轻松地遵循。
import time
# Wait for 3600 seconds
While True:
time.sleep(3600 )
#YOUR CODE HERE
If you want not to wait for the cell in running mode you can run the code above inside a thread 如果不想在运行模式下等待单元格,则可以在线程内运行上面的代码
Please setup a function that runs for an interval of 1 hour using the Javascript setInterval
function. 请使用Javascript setInterval
函数设置一个运行时间为1小时的函数。 Inside the interval function you can call the jupyter
object method, to run all cells. 在interval函数内部,您可以调用jupyter
对象方法来运行所有单元格。
%%html
<script>
// AUTORUN ALL CELLS ON NOTEBOOK-LOAD!
require(
['base/js/namespace', 'jquery'],
function(jupyter, $) {
$(jupyter.events).on("kernel_ready.Kernel", function () {
setInterval(function(){
console.log("Auto-running all cells-below...");
jupyter.actions.call('jupyter-notebook:run-all-cells-below');
// jupyter.actions.call('jupyter-notebook:save-notebook');
}, 60000); // 60000 for 1 hour interval gap
});
}
);
</script>
Note: I have added the setInterval
part of the script by myself, the major code,comes from this SO answer
注意:我自己添加了脚本的setInterval
部分,主要代码来自此SO answer
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.