Jupyter UI Poll

1.1.0 · active · verified Thu Apr 16

jupyter-ui-poll is a Python library that enables blocking Jupyter cell execution while interacting with ipywidgets or similar interactive elements. It addresses the challenge of creating 'blocking GUI' within notebooks, allowing for sequential workflows where user input via widgets is required before subsequent cells execute. The current version, 1.1.0, includes critical fixes for compatibility with newer `ipykernel` versions and improved handling of asynchronous operations. The library maintains an active release cadence, primarily driven by `ipykernel` compatibility updates.

Common errors

Warnings

Install

Imports

Quickstart

This quickstart demonstrates how to use `jupyter-ui-poll` to block cell execution until a user interacts with an `ipywidget`. A button is displayed, and the `ui_events` context manager is used to create a polling loop. The `poll(10)` call allows Jupyter to process UI events (like button clicks) while the `while` loop is active, ensuring the notebook doesn't hang. Once the button is clicked, the `ui_done` flag is set, and the cell execution proceeds.

import time
from ipywidgets import Button, display
from jupyter_ui_poll import ui_events

# Global flag to control the loop
ui_done = False

def on_click(btn):
    global ui_done
    ui_done = True
    btn.description = 'Done!'

# Create a button
button = Button(description='Click Me to Continue')
button.on_click(on_click)

display(button)

print('Waiting for button click...')

# Wait for user to press the button, processing UI events
with ui_events() as poll:
    while not ui_done:
        poll(10) # Process up to 10 UI events per call
        print('.', end='', flush=True)
        time.sleep(0.1) # Prevent busy-waiting

print('\nButton clicked! Execution continues.')

view raw JSON →