有没有办法在 VSCode Jupyter Notebook 中的单元完成执行时收到通知?

发布于 2025-01-10 21:19:34 字数 85 浏览 1 评论 0原文

我在 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?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(6

滴情不沾 2025-01-17 21:19:34

至关重要的是,没有人希望在每个单元格执行完成时收到通知。
相反,我们希望在长时间运行的单元完成时收到通知。因此,应该有一种方法来设置条件,使得如果单元格在该时间阈值内完成运行,则不会发出声音警报,但对于需要长时间运行的单元格,这些单元格会在完成后播放警报声音。

否则,您的笔记本电脑听起来就像一个由不必要的“误报”组成的管弦乐队,为短时间运行的单元演奏声音警报。

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.

入怼 2025-01-17 21:19:34

从 vscode v1.87 开始,此设置将是:

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

在 vscode v1.87 之前:

有要

Notebook Cell Completed
Notebook Cell Failed

添加到 vscode 的音频提示,请参阅 在单元执行时实现音频提示已完成

应位于设置音频提示:笔记本单元已完成音频提示:笔记本单元失败

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

烙印 2025-01-17 21:19:34

代码完成后,您可以在该部分的末尾播放声音。 :-P

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

这是一种创建音频警报的方法,如果它适合您的需要。您可以借用您所使用的任何操作系统附带的音频警报之一。

如果您正在寻找远程通知系统,您可以给自己发送电子邮件或设置一个 twilio 帐户。

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.

桃扇骨 2025-01-17 21:19:34

Telegram Bots API 是一个出色的工具。笔记本单元执行完成后,您可以使用 Python 的 Telegram API 库向手机和 PC 发送通知(或者如果需要,甚至可以发送图像?)。

为了能够使用它,您只需要获取 API 令牌(获取起来非常简单),在笔记本中添加几行代码,然后在工作结束时执行它。

要获取您的 API 令牌:
https://www.siteguarding.com/en/ how-to-get-telegram-bot-api-token

库的 PyPI 页面:
https://pypi.org/project/python-telegram-bot/

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

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

笑着哭最痛 2025-01-17 21:19:34
import winsound    
winsound.Beep(1440, 200)    

1440 音频(以赫兹为单位),
200 声音持续时间(以毫秒为单位)

import winsound    
winsound.Beep(1440, 200)    

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

关于从前 2025-01-17 21:19:34

考虑调用系统通知来发出警报。下面是一个示例:

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

如果您想将其保存为 VSCode 中的代码片段:

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

那么您可以输入 jnotify 来选择代码。

这对我在 Windows 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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文