clabe.runnable ¶
ActivityIndicator ¶
ActivityIndicator(
console: Console | None = None,
*,
enabled: bool | None = None,
)
Shared, thread-safe manager for a single live activity display.
Owns a single rich.progress.Progress instance into which any number of
concurrent runnables register an "activity". Because a terminal can only
host one live region at a time, every activity shares the same Progress
so concurrent spinners render as separate rows (each with its own spinner
and elapsed-time counter) instead of fighting over the terminal.
The display is reference-counted: it starts when the first activity is entered and stops (clearing itself) when the last activity exits. This works for both blocking synchronous code running on worker threads and asynchronous code driven by an event loop.
The indicator shares its Console with the logging handler so that log
lines emitted while the display is live render cleanly above the spinners
rather than corrupting them.
Attributes:
| Name | Type | Description |
|---|---|---|
enabled |
bool
|
Whether the display is active. Defaults to |
Example
Initialize the activity indicator.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
console
|
Console | None
|
Console to render on. Defaults to the shared console used by the logging handler so that logs and spinners coordinate. |
None
|
enabled
|
bool | None
|
Force the display on or off. When |
None
|
Source code in src/clabe/runnable/_activity.py
set_sink ¶
set_sink(sink: ActivitySink | None) -> None
Routes activities through sink (e.g. a TUI) instead of the console.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
sink
|
ActivitySink | None
|
The sink to render activities, or |
required |
Source code in src/clabe/runnable/_activity.py
observe ¶
observe(observer: ActivityObserver) -> Callable[[], None]
Registers observer to be entered around every activity, in addition to rendering.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
observer
|
ActivityObserver
|
Called with the activity description; returns a context manager. |
required |
Returns:
| Type | Description |
|---|---|
Callable[[], None]
|
A function that unregisters the observer. |
Source code in src/clabe/runnable/_activity.py
activity ¶
Display a spinner with elapsed time for the duration of the block.
Safe to nest and to use concurrently from multiple threads or coroutines. Registered observers are entered around the block whether or not the display is enabled.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
description
|
str
|
Text shown next to the spinner. |
required |
Source code in src/clabe/runnable/_activity.py
ActivitySink ¶
Bases: Protocol
An alternative destination for activity displays.
When a sink is registered on an ActivityIndicator, activities are
rendered through the sink instead of the rich console. This lets a live TUI
own the terminal and show progress inside itself, rather than having a
console-based spinner corrupt the TUI's display.
activity ¶
activity(description: str) -> AbstractContextManager[None]
RunnableSpec
dataclass
¶
RunnableSpec(
name: str | None = None,
notify: str | None = None,
show_activity: bool | None = None,
notify_start: bool | None = None,
notify_success: bool | None = None,
notify_fail: bool | None = None,
log_level: int = INFO,
)
Notification behaviour for a single @runnable.
All flags default to None (inherit) so that call-site rewraps can
override individual fields without clobbering the rest. The decorator
fills unset flags with True before storing the spec on the wrapper.
get_activity_indicator ¶
get_activity_indicator() -> ActivityIndicator
Return the process-wide shared ActivityIndicator.
Using a single shared indicator guarantees that concurrent runnables cooperate on one live display rather than each trying to start its own (which the terminal cannot support).
Returns:
| Name | Type | Description |
|---|---|---|
ActivityIndicator |
ActivityIndicator
|
The lazily-created shared indicator. |
Source code in src/clabe/runnable/_activity.py
runnable ¶
runnable(
fn: Callable[..., Any] | None = None,
*,
name: str | None = None,
notify: str | None = None,
show_activity: bool | None = None,
notify_start: bool | None = None,
notify_success: bool | None = None,
notify_fail: bool | None = None,
) -> Any
Wrap a callable with the shared runnable lifecycle (logging, activity spinner, notifications, and an OpenTelemetry span).
Use it as a decorator at definition time (@runnable or
@runnable(name=..., notify=...)) or to rewrap an existing callable at
the call site (runnable(obj.method, notify_success=False)()). Rewrapping
merges over the callable's existing spec rather than nesting, so it never
double-reports.
By default all notifications are on (start, success, failure). Pass
notify_start=False etc. to suppress individual ones.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
fn
|
Callable[..., Any] | None
|
The callable to wrap. Omit to use |
None
|
name
|
str | None
|
Display name. Derived from the instance class or function name when omitted. |
None
|
notify
|
str | None
|
Custom start message (shown instead of |
None
|
show_activity
|
bool | None
|
Show a spinner while running. Default |
None
|
notify_start
|
bool | None
|
Notify on start. Default |
None
|
notify_success
|
bool | None
|
Notify on success. Default |
None
|
notify_fail
|
bool | None
|
Notify on failure. Default |
None
|