I’m trying to write a Jupyterlab extension that triggers a notification when a notebook cell has finished executing if the execution took more than a certain amount of time. However, after exploring the API I haven’t been able to figure out how to listen for code execution messages. Any help would be greatly appreciated.
Hi @oriolmirosa, you can definitely listen to kernel status messages to get this information, but you may find it easier to use the somewhat under-documented
executed signal in the
NotebookActions namespace that is fired whenever a cell executes, with the notebook and cell as a payload. This may be a bit simpler to work with.
Thanks for your reply, @ian-r-rose, this looks promising. I haven’t been able to find how long the execution took in the
executed signal, however. Did I miss it, or is that something that’s not emitted?
I’m trying to build an extension for jupyterlab that does the same as Jupyter Notify, so I do need to know how long the cell execution took.
Thanks again for your help.
Ah, interesting. You may be interested in hooking into the new (ish) cell timing tracking that was implemented here. @saulshanabrook worked on that, and may have thoughts about good ways to surface it for notifications.
If not the cell timing approach, then the best way is probably to directly snoop for kernel
@oriolmirosa this sounds like a cool extension! Unofortunately, we don’t have an easy way to track this at the moment. You could watch on changes to the cell metadata for the finished timing key to be added, but this will only be activated when the user enables recording cell timing (https://github.com/jupyterlab/jupyterlab/pull/7578#issuecomment-561792168)
If you are OK with also recording the timing into the users notebooks, your extension could enable this setting when it is registered.
If you don’t want to however, you would have to snoop on the kernel messages. I don’t know off the top of my head how to do this, but if you need help on this approach I can do some digging.