Check for cell execution completion in Jupyterlab extension

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.

1 Like

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 execute_reply messages.

@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 (

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.

Thanks, @ian-r-rose and @saulshanabrook. I’m a bit at a loss here, but I’ve found a couple of extensions that listen to kernel messages, so I’ll start from them and hopefully I’ll have something working soon.

@oriolmirosa any progress on this? As far as I can tell, there’s still no cell completion notification extension for Jupyter lab

No, @nick-youngblut, I haven’t made any progress on this. Between the pandemic, work and kids this ended up falling through the cracks. I still plan on working on this when I have some time, but with a new baby on the way in the next couple of months it might be a while.

I created one that supports both jupyter notebook and jupyter lab.