Skip to main content

ipython_blocking offers a context manager and IPython magic to capture cell execution.

Project description

ipython_blocking

A Python library that offers a context manager to turn on cell execution capture/blocking in Jupyter notebooks/IPykernel. Useful when you need a "blocking widget".

Use-case

The intended use-case of this library was to handle "blocking" until a widget value changed or was filled out to satisfy some validation function. Widgets are often used in notebooks to offer elegant and robust form input for queries to remote API's or other complex query inputs. Unfortunately, it's typical that the rest of the code in a "widget-based notebook" ends up being created as callbacks and is forced into a style that is hard to read, hard to debug, and hard to manipulate.

ipython_blocking offers a way to capture cell execution requests and then replay them after a condition is met, such as a widget changing value or other validation function is met. That effectively "blocks" a notebook so that you can write regular non-callback code that expects to access a widget's value directly and will only run after an appropriate value is set.

Examples

See the demo notebook for an interactive example. The following gifs demonstrate the problem and the proposed solution in the ipython_blocking package.

The problem

Problem demo

Solution -- magic for widget change

If the argument in the %block line magic is a Widget instance, then the cell execution capture contex will stop when that widget has changed value. Widget change demo

Solution -- magic for an arbitrary break function

If the argument in the %block line magic is a function or class method, then the cell execution capture context will stop when that function or method evaluates to True.
Widget function demo

Project details


Download files

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

Source Distributions

No source distribution files available for this release.See tutorial on generating distribution archives.

Built Distribution

ipython_blocking-0.1.0-py2.py3-none-any.whl (7.7 kB view details)

Uploaded Python 2 Python 3

File details

Details for the file ipython_blocking-0.1.0-py2.py3-none-any.whl.

File metadata

File hashes

Hashes for ipython_blocking-0.1.0-py2.py3-none-any.whl
Algorithm Hash digest
SHA256 968b10d34c00ee8975a6cf77eb9c645c9f55743cef1579ea8af74755ddf1f3d0
MD5 481570c9b11decd4ffafee7c852ed1ef
BLAKE2b-256 23f7afb602911486afb741a58dd55b0344766100747c7b67dda90b953eda66d2

See more details on using hashes here.

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