.md →
AsyncFlow API#
Bases: AnyWidget
Live, source-linked timeline of a single async run.
Runs a coroutine on the notebook's own event loop and streams its task
activity — spawn, suspend-at-await, resume, done — into a swimlane
timeline that fills in as the run proceeds. One lane per task; solid bars are
running, hatched bars are suspended at an await.
Example (marimo, top-level await)::
import asyncio
from wigglystuff import AsyncFlow
async def worker(name, delay):
await asyncio.sleep(delay)
return name
async def main():
return await asyncio.gather(worker("A", 0.3), worker("B", 0.1))
flow = await AsyncFlow.trace(main()) # displays live, returns the widget
flow.result # ['A', 'B']
Requires sys.monitoring (Python 3.12+).
Source code in wigglystuff/async_flow.py
run
async
#
Drive coro to completion, streaming events into the widget.
targets (functions/coroutines) add extra source files to capture;
by default only the file of coro is tracked, which already picks up
any coroutine defined alongside it.
Source code in wigglystuff/async_flow.py
trace
async
classmethod
#
trace(coro: Any, *, targets: Iterable[Any] | None = None, poll_ms: int = 100, width: int = 0) -> 'AsyncFlow'
Create the widget, display it, and trace coro live.
Returns the widget; the coroutine's return value is on .result.
Source code in wigglystuff/async_flow.py
Synced traitlets#
| Traitlet | Type | Notes |
|---|---|---|
events |
list[dict] |
Captured event stream; re-synced on every poll tick so the timeline grows live. Each entry has t_ms, coro, event, task, line, detail. |
now_ms |
float |
Elapsed wall-clock milliseconds; advances every tick so suspended bars keep growing during long sleeps. |
running |
bool |
Whether a run is currently in flight. |
width |
int |
Widget width in pixels; 0 grows to fit. |