{"id":"ftl2-htop-tui-dual-thread-architecture","text":"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`.","truth_value":"IN","source":"entries/2026/05/11/ftl2-htop-tui.md","source_url":"","source_hash":"","justifications":[],"dependents":[],"metadata":{"example":"# From ftl2-servercraft/tui.py — automation runs in daemon thread\ndef _thread_target():\n    loop = asyncio.new_event_loop()\n    asyncio.set_event_loop(loop)\n    async def _run():\n        async with automation(...) as ftl:\n            await script.provision(ftl, config, _log_callback)\n    loop.run_until_complete(_run())\n    loop.close()\n\nthread = threading.Thread(target=_thread_target, daemon=True)\nthread.start()\n# TUI updates via call_from_thread()"},"explanation":{"steps":[{"node":"ftl2-htop-tui-dual-thread-architecture","truth_value":"IN","reason":"premise"}]}}