4
4

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 5 years have passed since last update.

【OS X】Jupyterlabで通知機能が欲しい

Last updated at Posted at 2019-01-29

jupyter上で重たい計算が終わるのを待っているとそわそわします。
普通のループ計算だとtqdmで進捗確認できたりするんですけど、データサイズの大きなグラフの描画や計算中に別の作業をしている場合に通知機能が欲しくなります。
jupyterからの通知を実現するjupyter-notifyなるものがあるのですが、notebook向けに作られておりissueにある通りJupyterlabには未対応のようです。(2019/1/29時点)
また、notify-runを使えばスマホに通知を飛ばせてかなり便利なんですがPCのみで完結したい時もあります。
Mac使いでなおかつローカル環境で実行している場合の解決方法を備忘録として残します。(リモートの場合はめんどくさそう..)

方法

コマンドラインからポップアップ通知をするalerterコマンドを使用します。(インストールはリンク先参照)
JupyterLab上で実行できることを確認。

!alerter -sound default -message finished.

通知音と共に画面右上に通知が表示されます。
image.png

マジックコマンドとして使う

Jupyterlabの裏で動作しているIpythonのコンフィグファイル(~/.ipython/profile_default/startup/startup.py)に以下を追記すればマジックコマンドとして使えます。

startup.py
import os
from IPython.core.magic import register_line_cell_magic


@register_line_cell_magic
def alert(line, cell=None):
    os.system(
        f'alerter -sound default '
        ' -title JupyterLab '
        ' -appIcon ~/Pictures/jupyter.png '
        ' -message finished. '
    )

(alerterコマンドの-appIconオプションは通知のアイコンを指定する部分なので適当な画像拾ってきて下さい)

何かしらの重たい処理をするセルの直後に以下を追加し、一緒に実行すると計算が終わったタイミングで通知が届きます。

%alert

image.png

参考

4
4
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
4
4

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?