Running a process in the background in Jupyter

て烟熏妆下的殇ゞ 提交于 2020-02-03 16:23:31

问题


In a Jupyter notebook, if I run a cell that takes a long time, I cannot run any other cell until the first cell is computed.

Is there a way to tell Jupyter to run a cell in a background process, so that I can continue to run other cells?


回答1:


I tried this using Multiprocessing and found it does not work, I've no idea if this is a limitation of Windows or recent Jupyter/Python.

So instead I created a solution using Threading, based on this work:
https://gist.github.com/maartenbreddels/3378e8257bf0ee18cfcbdacce6e6a77e All credit to author of this Gist

This method hooks the 0MQ event loop that IPython uses internally to perform work by submitting callbacks to the same event loop.

I've prepared an example Jupyter Notebook Gist is here:
https://gist.github.com/the-moog/94b09b49232731bd2a3cedd24501e23b

This example updates a pair of progress bars asynchronously, you should be able to replace the callback with code that performs other tasks.

(I'm not a fan of links in posts. If anybody knows how to render notebook views directly into stackoverflow, let me know)



来源:https://stackoverflow.com/questions/47052886/running-a-process-in-the-background-in-jupyter

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!