Textual Async Data Loading logo

Textual Async Data Loading

Community
st1page
textual-async-data-loading

textual TUI 异步数据加载完整模式:@work(thread=True) 后台执行阻塞 IO → call_from_thread 回主线程渲染 → LoadingIndicator 过渡 → exclusive group 防抖 → dict 缓存 + stale check 防竞态

Overview

Publisherst1page
Repositoryagent-knowledge-framework
Skill nametextual-async-data-loading
Stars
42
Forks
6
Bundled files
Instructions only
LicenseApache-2.0
Links
  • Markdown instructions

    A SKILL.md file the model loads on demand, so it only costs tokens when a request actually matches.

  • Works with any LLM

    AI skills are plain Markdown, not provider-specific code, so this works with GPT, Claude, Gemini, Grok, or a local model.

  • Self-contained

    Everything the model needs lives in the instructions — no extra files to sync.

  • Open source

    Published by st1page on GitHub. Read the source before you install it.

Installation

Install the Textual Async Data Loading AI skill in TypingMind to use it with any LLM, or drop it into another agent that reads SKILL.md.

1

Install in TypingMind

TypingMind installs a skill straight from its GitHub folder — it reads SKILL.md, bundles the resource files, and stores the result locally.

  1. Open the app and go to Plugins → Skills.
  2. Choose "Install from GitHub".
  3. Paste the skill folder URL below and confirm.
    https://github.com/st1page/agent-knowledge-framework/tree/main/roles/cli-tool-dev/skills/textual-async-data-loading
  4. Enable the skill in any chat where you want it available.
Plugins → Skills → Add skill → From GitHub URL, then paste the folder URL and press Continue.
2

Install in another agent

Any agent that reads the Agent Skills format can use this skill — copy the folder into that agent's skills directory.

Claude Code — .claude/skills
git clone --depth 1 https://github.com/st1page/agent-knowledge-framework.git /tmp/agent-knowledge-framework
mkdir -p .claude/skills
cp -r /tmp/agent-knowledge-framework/roles/cli-tool-dev/skills/textual-async-data-loading .claude/skills/textual-async-data-loading
Restart Claude Code after copying so it picks up the new skill.

Use it in TypingMind

Enable Textual Async Data Loading in any TypingMind chat and the model takes it from there. Its name and description sit in the system prompt, and the moment a request matches, the model loads the full instructions itself — you never invoke it by hand, and it costs no tokens until it is actually used.

The model loads Textual Async Data Loading on its own as soon as a request matches it.

Works with any AI model

AI skills are plain Markdown instructions rather than provider-specific code, so Textual Async Data Loading is not tied to the model it was written for. Install it once in TypingMind and use it with GPT-5, Claude, Gemini, Grok, DeepSeek, Mistral, Llama, or a local model you run yourself — all on your own API keys.

  • Loaded only when it is needed

    The system prompt carries just the name and description. The instructions are fetched on the first matching request, so an idle skill costs nothing.

  • Switch models mid-chat

    Because the skill is instructions rather than code, changing model does not break it — the next model reads the same SKILL.md.

Skill instructions

This is the SKILL.md content the model loads. Read it before installing — a skill is instructions your model will follow.

textual TUI 异步数据加载模式

目标:在 textual TUI 中执行阻塞 IO(subprocess、HTTP)时,保持 UI 响应,同时避免竞态和重复请求。

核心三件套

1. @work(thread=True) — 阻塞 IO 移出 UI 线程

python
from textual import work  # 注意:不是 from textual.work import work

@work(thread=True)
def _fetch_data(self) -> None:
    result = subprocess.run(...)  # 在后台线程执行
    self.app.call_from_thread(self._render, result)  # 回主线程更新 UI

陷阱:from textual.work import work 会 ModuleNotFoundError。

2. LoadingIndicator — 加载过渡

compose 时同时 yield 数据 widget 和 loading indicator,用 display 属性互斥切换:

python
def compose(self) -> ComposeResult:
    yield LoadingIndicator(id="loading")
    yield DataTable(id="table", cursor_type="row")

def on_mount(self) -> None:
    self.query_one("#table").display = False  # 初始隐藏数据

def _render(self, data) -> None:
    self.query_one("#loading").display = False
    self.query_one("#table").display = True
    # ... 填充数据

3. call_from_thread — worker 回调回主线程

worker 线程中不能直接操作 UI widget。必须通过 self.app.call_from_thread(callback, *args) 调度回主线程。

增强模式

4. exclusive worker group — 高频触发防抖

光标快速移动时,每次触发数据请求。用 exclusive=True + group 自动取消旧请求:

python
@work(thread=True, exclusive=True, group="jobs")
def _fetch_jobs(self, run_id: int) -> None:
    ...

效果:连续触发只执行最后一个请求。

5. dict 缓存 + stale check

简单 dict 缓存已请求过的数据;异步回调时检查数据是否仍然是当前需要的:

python
_cache: dict[int, Data] = {}

@work(thread=True, exclusive=True, group="jobs")
def _fetch_jobs(self, run_id: int) -> None:
    if run_id in self._cache:
        self.app.call_from_thread(self._render_jobs, run_id, self._cache[run_id])
        return
    result = fetch(run_id)
    self._cache[run_id] = result
    # stale check:渲染前确认用户没有切走
    if self._selected_run_id == run_id:
        self.app.call_from_thread(self._render_jobs, run_id, result)

刷新时清空整个 cache(CLI 工具生命周期短,不需要 TTL)。

headless 测试中等待 worker

pilot.pause() 只处理事件队列,不等 worker 线程。必须轮询:

python
async def wait_workers(app, pilot, timeout=15):
    import asyncio
    for _ in range(int(timeout / 0.1)):
        await pilot.pause()
        if all(w.is_finished for w in app.workers):
            return
        await asyncio.sleep(0.1)
    raise TimeoutError("workers not finished")

Escalate to experience if

  • 遇到 @work 的 import 路径报错或 call_from_thread 在测试中行为异常
  • exclusive group 取消旧 worker 后出现数据丢失
  • 需要评估缓存策略(TTL vs 手动刷新 vs LRU)

Frequently asked questions

What does the Textual Async Data Loading AI skill do?

textual TUI 异步数据加载完整模式:@work(thread=True) 后台执行阻塞 IO → call_from_thread 回主线程渲染 → LoadingIndicator 过渡 → exclusive group 防抖 → dict 缓存 + stale check 防竞态

Why use Textual Async Data Loading on TypingMind?

Because you install it once and use it with any model. Textual Async Data Loading is plain Markdown rather than provider-specific code, so the same skill runs on GPT-5, Claude, Gemini, Grok, or a local model — and you can switch model mid-chat without it breaking. TypingMind runs on your own API keys, so you pay providers directly instead of a per-seat subscription, and your skills and chats stay in your own storage.

How do I install Textual Async Data Loading in TypingMind?

Open Plugins → Skills → Install from GitHub in TypingMind and paste https://github.com/st1page/agent-knowledge-framework/tree/main/roles/cli-tool-dev/skills/textual-async-data-loading. TypingMind reads its SKILL.md and installs it as a skill you can enable per chat.

Which AI models can use Textual Async Data Loading?

Any model you connect in TypingMind. AI skills are plain Markdown instructions rather than provider-specific code, so GPT, Claude, Gemini, Grok, and local models can all load this skill when a request matches it.

How many AI models can I use with Textual Async Data Loading?

As many as you like. As long as a model supports skills, you can use Textual Async Data Loading with it — GPT, Claude, Gemini, Grok, DeepSeek, Mistral, Llama and more — all on TypingMind with your own API keys.

Is the Textual Async Data Loading AI skill free?

Yes. It is published on GitHub by st1page under the Apache-2.0 license. You only pay your own AI provider for the tokens you use.

What are AI skills?

An AI skill is a reusable instruction bundle that teaches an AI model how to do one specific task. It follows the open Agent Skills format: a SKILL.md file with a name and description, plus any scripts, templates or reference files the model may need. The model reads the instructions only when your request matches the skill, so an installed skill costs nothing until it is used.

How are AI skills different from plugins or MCP servers?

A plugin or MCP server gives a model new tools to call — code that runs somewhere and returns a result. An AI skill gives the model knowledge and process instead: how to approach a task, which steps to follow, what good output looks like. Skills are plain Markdown, so they need no server, no API key and no runtime, and they work with any model.

View all

Set up your own AI workspace now

Get notified about new features and future giveaways by subscribing to our newsletter 👇