At a glance
- Colab's own notification shows only on your computer, while the tab is open.
- A webhook call at the end of the cell reaches your phone.
- Free runtimes run at most 12 hours; a disconnect skips your last line.
- A stall alert from outside the notebook catches disconnects.
Colab's built-in browser notification
Colab can show a browser notification when a cell finishes while you are looking at another tab. You turn it on in Colab's settings, and it applies to all cells rather than one.
For the popup to appear, notifications must be allowed in two places:
- Your browser's site settings for
colab.research.google.com - Your operating system's settings for the browser itself
In Colab's issue tracker in August 2023, a user had Chrome set up correctly and still saw nothing; macOS was blocking notifications from Chrome. This alert only fires while the Colab tab stays open on your computer, and it never reaches your phone.
Play a sound when the cell ends
If you stay within earshot, end the cell with a beep. IPython's Audio object with autoplay=True plays a generated tone in the notebook output. Chrome only allows autoplay with sound after you have interacted with the site, so run a short test cell before the long job.
import numpy as np
from IPython.display import Audio, display
def beep(seconds=0.5, freq=880, rate=22050):
t = np.linspace(0, seconds, int(rate * seconds), endpoint=False)
display(Audio(np.sin(2 * np.pi * freq * t), rate=rate, autoplay=True))
train()
beep()Send a phone alert from the last line
To get an alert on your phone, post to a Discord webhook or a Telegram bot at the end of the cell. Wrap the work in try/except so a crash sends a message too.
- Keep the webhook URL or bot token in Colab's Secrets panel and read it with
google.colab.userdata.get(). Secrets are only available when the notebook runs from the Colab UI. - A Discord webhook takes JSON with
contentup to 2,000 characters. - Telegram's
sendMessagetakes text from 1 to 4,096 characters.
import requests
from google.colab import userdata
DISCORD_WEBHOOK_URL = userdata.get("DISCORD_WEBHOOK_URL")
def send(text):
try:
requests.post(DISCORD_WEBHOOK_URL, json={"content": text[:2000]}, timeout=10)
except requests.RequestException as exc:
print(f"notification failed: {exc!r}")
try:
train()
except Exception as exc:
send(f"Colab cell crashed: {exc!r}")
raise
else:
send("Colab cell finished")When the runtime disconnects, nothing runs
Free Colab notebooks run for at most 12 hours, depending on availability and usage patterns, and idle runtimes time out sooner. Colab doesn't publish the idle timeout. Colab Pro+ supports continuous execution for up to 24 hours if you have enough compute units, and idle timeouts only apply once code execution ends.
When a runtime disconnects or is reclaimed, the rest of the cell never runs, so a notification on the last line never fires. To hear about a dead runtime, something outside the notebook has to notice the silence.
A notebook kernel keeps running after the cell ends and IPython handles cell exceptions itself, so the two end_run() calls report the result. Use the drop-in import in notebooks, since the tqdm.notebook widget bar is not streamed.
Options compared
| Method | Reaches you | Works with the tab closed | Catches a disconnect |
|---|---|---|---|
| Colab browser notification | Your computer, while on another tab | No | No |
Sound with IPython Audio | Within earshot of your computer | No | No |
| Discord or Telegram from the cell | Your phone | Only while the runtime keeps running | No |
| Runpeek stall alert | Discord, Slack or a webhook, plus a live link | Yes | Yes |
FAQ
Does Colab notify you when a cell finishes?
Yes. Colab has a setting that shows a browser notification when a cell completes while you are on another tab. It applies to all cells, and both your browser and your operating system must allow notifications from it.
Will my code keep running if I close the Colab tab?
Execution after you close the tab, called background execution, is a feature of the higher paid plans; Pro+ runs continuously for up to 24 hours with enough compute units. Browser notifications and sounds only work while the tab is open.
How long can a Colab notebook run?
Free Colab notebooks run for at most 12 hours, depending on availability and usage patterns, and idle runtimes time out sooner. Colab Pro+ supports continuous execution for up to 24 hours when you have enough compute units.
How do I keep a webhook URL out of my notebook?
Save it in Colab's Secrets panel and read it with google.colab.userdata.get(). The URL then never appears in the notebook's code or output. The first time, Colab asks you to grant the notebook access to that secret.
Why did my Colab notification not arrive?
For the built-in notification, check that your browser allows notifications from colab.research.google.com, that your operating system allows them from the browser, and that you were on another tab. For a webhook or sound at the end of the cell, the runtime may have disconnected before the last line ran.
Check on long runs from your phone
Change one import and every tqdm bar prints a link you can open on any device. Get a Discord or Slack message when the run finishes, fails or stalls.
pip install tqdm-liveSources
- Google Colab FAQ: limits and paid plans research.google.com
- Colab issue 3973: browser notifications for finished cells github.com
- Colab source: google.colab.userdata github.com
- IPython docs: display.Audio ipython.readthedocs.io
- Chrome: Autoplay policy developer.chrome.com
- Discord developer docs: Execute Webhook docs.discord.com
- Telegram Bot API: sendMessage core.telegram.org