I like to set up long-running tasks to play a beep at the end so that I can temporarily turn my attention to another tab or window, yet not miss the task’s conclusion.
I found that you can do this in Jupyter notebooks via defining the following function in a cell:
%%javascript
// Original source -- https://gist.github.com/xem/670dec8e70815842eb95
Jupyter.beep = () => {
var A=new AudioContext();
var o = A.createOscillator();
o.connect(A.destination);
o.start(0);
var duration = 500;
setTimeout(function(){o.stop(); A.close();}, duration);
}
Then, when you want the beep, create a cell that has this in it:
%%javascript
Jupyter.beep();
(I believe you can’t mix Python and Javascript in one cell.)
FYI, it is even easier to play a beep from the shell. If you want a beep after somecommand, do this:
For jobs which only take a few minutes, I don’t bother with sending the notification to my phone; a beep is enough for me. For long jobs, yeah, getting a notification on my phone is great.
import telegram # https://github.com/python-telegram-bot/python-telegram-bot
api_token = 'yourtoken' # API token for telegram bot, you'll need to get a token
chat_id = 'youruser' # Chat token to specify your user ID; I forget how I found this
# Initialize bot
bot = telegram.Bot(token=api_token)
# Confirm successfully initialized
print(bot.get_me())
# Send message
bot.send_message(chat_id=chat_id, text='Your job finished!')
Great approach! My approach was to copy an mp3 of a beep onto the server, and then use IPython.display.Audio to play it in a cell. Your idea is better since it doesn’t require the copy step.
I’ve used flowmatters for sending notifications to my slack channel (my org uses slack) and it’s been great. Not only does it send notifications, it also sends the error outputs so you can see if a job or run has failed.
Works great for long running jobs on remote machines.
I like https://github.com/ShopRunner/jupyter-notify which is based on browser notifications. the cool feature about it is that you can put a %autonotify -a 15
at the top of your notebook so any cell lasting more than 15 seconds will trigger a notification automatically. It definitely increased my productivity, even if i get distracted and go to another browser tab or anything else, i come back to my notebook as soon as jupyter is ready.