The kernel should know that it has outstanding requests, so you ought to be able to query that, to determine whether.
There isn’t a public API for this information, but this should work for now:
finished = (Object.keys(IPython.notebook.kernel._msg_callbacks).length == 0);
If you check that value when idle events arrive, it should tell you when the notebook is actually done or not.
-MinRK
Hi all--I'm trying to have a custom.js that will automatically run a notebook when it gets opened or reloaded, and then hook an event handler when done.I'm trying this to start:require(['base/js/namespace', 'base/js/events', 'base/js/dialog', 'base/js/utils', 'base/js/security'], function() {$([IPython.events]).on('kernel_ready.Kernel kernel_created.Session notebook_loaded.Notebook', run_notebook);});That seems to work okay.Getting completion event handling seems more tricky. I have:function run_notebook() {var pageClass = document.body.className;if (pageClass.indexOf('notebook_app') >= 0) {IPython.notebook.clear_all_output();IPython.notebook.execute_all_cells();// My problem is here - how to tell when done.// One attempt - this seems to run over and over$([IPython.events]).on('kernel_idle.Kernel', function() {checkIfDone();});// Another attempt - this doesn't seem to work at allsetTimeout(5000, function() {checkIfDone();});}}function checkIfDone() {if (IPython.notebook.kernel_busy) {setTimeout(5000, function() {checkIfDone();});} else {console.log('Finished execution');}}Is there a better way? Some other event to hook into?Thanks!
You received this message because you are subscribed to the Google Groups "Project Jupyter" group.
To unsubscribe from this group and stop receiving emails from it, send an email to jupyter+u...@googlegroups.com.
To post to this group, send email to jup...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/jupyter/0982776e-ea36-447c-a45c-d6c75775cb3f%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
To unsubscribe from this group and stop receiving emails from it, send an email to jupyter+unsubscribe@googlegroups.com.
To post to this group, send email to jup...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/jupyter/8f7d5e8e-bcb8-47cf-9616-386126f4bda6%40googlegroups.com.