ftl2-htop-tui-dual-thread-architecture

Status: IN

The Textual TUI mode uses a dual-thread architecture: Textual event loop on the main thread, FTL2 automation on a daemon thread with its own asyncio event loop; cross-thread updates use `call_from_thread`.

Source: entries/2026/05/11/ftl2-htop-tui.md

Example

# From ftl2-servercraft/tui.py — automation runs in daemon thread
def _thread_target():
    loop = asyncio.new_event_loop()
    asyncio.set_event_loop(loop)
    async def _run():
        async with automation(...) as ftl:
            await script.provision(ftl, config, _log_callback)
    loop.run_until_complete(_run())
    loop.close()

thread = threading.Thread(target=_thread_target, daemon=True)
thread.start()
# TUI updates via call_from_thread()

JSON