Skip to main content

IPython/Jupyter cell magic to execute code after a cell succeeds or fails

Project description

on-done

on-done is an IPython/Jupyter cell magic to execute code after a cell succeeds or fails. It is especially useful if you need a way to alert yourself that your code has terminated.

It is inspired by this Stack Overflow answer by Colin Carroll.

Example Usage

Start by launching an IPython session:

$ ipython
Python 3.10.5 (main, Jun  6 2022, 18:49:26) [GCC 12.1.0]
Type 'copyright', 'credits' or 'license' for more information
IPython 8.4.0 -- An enhanced Interactive Python. Type '?' for help.

Then, load the extension:

In [1]: %load_ext on_done

Next, define a function to alert you that your code has terminated.

In [2]: from datetime import datetime
   ...: import sys
   ...:
   ...: def alert():
   ...:     sys.stderr.write(f'Cell terminated at {str(datetime.now())}\n')

Note that in the above, a message is written to stderr. You may instead want to send yourself an email, text message, Slack alert, etc.

Let's test it:

In [3]: %%on_done alert()
   ...: import numpy as np
   ...:
   ...: np.random.randn(10**8)
Cell terminated at 2022-07-20 13:31:45.690233

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

on-done-0.1.0.tar.gz (2.9 kB view hashes)

Uploaded Source

Built Distribution

on_done-0.1.0-py3-none-any.whl (3.2 kB view hashes)

Uploaded Python 3

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page