Sruthi
Sruthi

Reputation: 3018

Is there a way to be notified when a cell finishes execution in VSCode Jupyter Notebook?

I'm using Jupyter Notebook on VSCode and would like to be notified when a cell finishes execution. I searched and was not able to find any extension for this task. Is there a way to get this working?

Upvotes: 14

Views: 7952

Answers (6)

shiquda
shiquda

Reputation: 11

Consider calling a system notification for alerts. Here's an example:

from plyer import notification
notification.notify(message='Jupyter Finished!')

And if you'd like to save it as a snippet in VSCode:

    "Jupyter Notification": {
        "prefix": "jnotify",
        "body": [
            "from plyer import notification",
            "notification.notify(message='Jupyter Finished!')"
        ],
        "description": "Send a notification when Jupyter finishes"
    }

Then you can type jnotify to select the code.

This works for me on Windows 11.

Upvotes: 1

Mark
Mark

Reputation: 182761

As of vscode v1.87 this settings will be:

Accesibility > Signals: Notebook Cell Completed
Accesibility > Signals: Notebook Cell Failed

Prior to vscode v1.87:

There are audio cues for

Notebook Cell Completed
Notebook Cell Failed

being added to vscode, see Implement Audio cues on cell execution completed.

Should be under the setting Audio Cues: Notebook Cell Completed and Audio Cues: Notebook Cell Failed

Upvotes: 10

Vegarus
Vegarus

Reputation: 480

import winsound    
winsound.Beep(1440, 200)    

1440 tone frequency (in Hertz), 200 sound duration (in milliseconds)

Upvotes: 2

Sirius Bey
Sirius Bey

Reputation: 109

The Telegram Bots API is an excellent tool for this. After the execution of your notebook cell finishes, you can send notifications both to your phone and PC (or you can even send images if you want?) by using the Telegram API library of Python.

To be able to use it, you just need to get your API token (which is extremely simple to get), add a few lines of code to your notebook, and execute it at the end of your job.

To get your API token: https://www.siteguarding.com/en/how-to-get-telegram-bot-api-token

PyPI page of the library: https://pypi.org/project/python-telegram-bot/

The Documentation: https://docs.python-telegram-bot.org/en/v20.0a6/telegram.bot.html#telegram.Bot.send_message

Upvotes: 2

JohnnyUtah
JohnnyUtah

Reputation: 555

Crucially, nobody wants to be notified when each and every cell is done executing. Rather, we want to be notified when a long-running cell finishes. So there should be a way to set a conditional such that if a cell finishes running under that threshold of time, there's no sound alert, but for the cells that take a long time to run, those cells play the alert sound upon completion.

Otherwise your notebook will sound like an orchestra of unnecessary "false positives" playing audible alerts for short-running cells.

Upvotes: 10

FlippinBits
FlippinBits

Reputation: 185

You could play a sound at the end of your Section after your code finishes. :-P

from playsound import playsound
playsound('/path/to/note.wav') # .wav file
playsound('/path/to/note.mp3') # .mp3 file

It's a way of creating an audio alert, if that suits your needs. You can borrow one of the audio alerts that come with whichever OS you are using.

If you are looking for a remote notification system, you could maybe email yourself or setup a twilio account.

Upvotes: 5

Related Questions