有没有办法在 VSCode Jupyter Notebook 中的单元完成执行时收到通知?
我在 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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(6)
至关重要的是,没有人希望在每个单元格执行完成时收到通知。
相反,我们希望在长时间运行的单元完成时收到通知。因此,应该有一种方法来设置条件,使得如果单元格在该时间阈值内完成运行,则不会发出声音警报,但对于需要长时间运行的单元格,这些单元格会在完成后播放警报声音。
否则,您的笔记本电脑听起来就像一个由不必要的“误报”组成的管弦乐队,为短时间运行的单元演奏声音警报。
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.
从 vscode v1.87 开始,此设置将是:
在 vscode v1.87 之前:
有要
添加到 vscode 的音频提示,请参阅 在单元执行时实现音频提示已完成。
应位于设置
音频提示:笔记本单元已完成
和音频提示:笔记本单元失败
As of vscode v1.87 this settings will be:
Prior to vscode v1.87:
There are audio cues for
being added to vscode, see Implement Audio cues on cell execution completed.
Should be under the setting
Audio Cues: Notebook Cell Completed
andAudio Cues: Notebook Cell Failed
代码完成后,您可以在该部分的末尾播放声音。 :-P
这是一种创建音频警报的方法,如果它适合您的需要。您可以借用您所使用的任何操作系统附带的音频警报之一。
如果您正在寻找远程通知系统,您可以给自己发送电子邮件或设置一个 twilio 帐户。
You could play a sound at the end of your Section after your code finishes. :-P
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.
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
1440 音频(以赫兹为单位),
200 声音持续时间(以毫秒为单位)
1440 tone frequency (in Hertz),
200 sound duration (in milliseconds)
考虑调用系统通知来发出警报。下面是一个示例:
如果您想将其保存为 VSCode 中的代码片段:
那么您可以输入
jnotify
来选择代码。这对我在 Windows 11 上有效。
Consider calling a system notification for alerts. Here's an example:
And if you'd like to save it as a snippet in VSCode:
Then you can type
jnotify
to select the code.This works for me on Windows 11.