MCPcopy Create free account
hub / github.com/agentforce314/clawcodex / _exit_when_stdin_closes

Function _exit_when_stdin_closes

src/entrypoints/agent_server_cli.py:37–56  ·  view source on GitHub ↗

Exit the process when stdin reaches EOF (parent TUI went away). The Ink TUI spawns this server with stdin wired to a pipe it holds open. If the TUI exits — even a hard crash that skips its cleanup — the OS closes that pipe, stdin EOFs here, and we exit. Mirrors hermes's gateway, which

()

Source from the content-addressed store, hash-verified

35
36
37def _exit_when_stdin_closes() -> None:
38 """Exit the process when stdin reaches EOF (parent TUI went away).
39
40 The Ink TUI spawns this server with stdin wired to a pipe it holds open.
41 If the TUI exits — even a hard crash that skips its cleanup — the OS closes
42 that pipe, stdin EOFs here, and we exit. Mirrors hermes's gateway, which
43 exits on stdin EOF when its Node parent goes away. Daemon thread so it never
44 blocks normal shutdown.
45 """
46 import os as _os
47 import threading as _threading
48
49 def _watch() -> None:
50 try:
51 sys.stdin.buffer.read() # blocks until the parent closes the pipe
52 except Exception: # noqa: BLE001
53 pass
54 _os._exit(0)
55
56 _threading.Thread(target=_watch, name="agent-server-parent-watch", daemon=True).start()
57
58
59def run_agent_server_subcommand(argv: list[str]) -> int:

Callers 1

Calls 1

startMethod · 0.45

Tested by

no test coverage detected