Workaround for wrapping a JS function in python in Jupyter notebook

血红的双手。 提交于 2019-12-06 03:04:54

Code sent to the kernel is executed one snippet at a time. Although you're calling sleep, the cell is still executing. So the snippet sent by JS won't be executed until after the cell is done, as you've observed.

If you want to do something asynchronously, you could send a custom message through the Jupyter protocol from the browser to the kernel, and install a custom message handler in the Python kernel to process it. Some attempts in that direction are linked in the "Previous work" section of IPEP-8:

https://github.com/ipython/ipython/wiki/IPEP-8:-Custom-messages-and-message-handlers#previous-work

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