Skip to content

Concept: Drive terminal subprocesses from synchronous Python - #142

Draft
tony wants to merge 5 commits into
masterfrom
concept/terminal-subprocess
Draft

tony wants to merge 5 commits into
masterfrom
concept/terminal-subprocess

Conversation

@tony

@tony tony commented Dec 1, 2026 •

Copy link
Copy Markdown
Member

Summary

  • Drive a PTY or ConPTY from synchronous Python with open_terminal().
  • Collect exit status, an immutable screen and a bounded output tail with run_terminal().
  • Preserve ordinary Popen and run as their actual typed standard library callables.

Closes #106.

Process exit and terminal EOF

A direct child can exit while a worker still reads and writes the inherited terminal. wait() returns the direct child's status. wait_eof() collects the worker's final output. Closing the handle owns the terminal and reaps the direct child. A POSIX descendant that ignores hangup may survive a close or timeout after its parent exits.

On macOS a helper owns the controlling terminal until the session closes. The helper uses the process temporary directory for its control socket. Set a short TMPDIR if the path exceeds the Unix socket address limit. Native tests cover descendant I/O, the foreground process group, Ctrl+C status and helper cleanup.

Windows terminal mode uses ReleasePseudoConsole to observe EOF when the final console client disconnects. Microsoft provides that API starting with Windows 11 24H2 and Windows Server 2025, build 26100. Windows API reference

Try it

Run the synchronous input, resize, status, and EOF cases from a libvt checkout.

$ gh pr checkout 142 && uv run --frozen --all-groups --all-extras pytest -q tests/test_subprocess.py

Test plan

  • Drive a child on Linux, send keys and paste, resize, and collect its final screen. The earlier PR checklist recorded macOS and native Windows coverage.
  • Let a worker accept input after the direct child exits, then wait for actual EOF.
  • Stop a real Python debugger at a breakpoint and assert the value of a local expression on Linux. The earlier PR checklist also recorded the Windows debugger check.
  • Check ordinary text and bytes inference and invalid calls across Python 3.12–3.15 type targets.
  • Exercise one-shot timeout, nonzero exit, bounded recording, missing executable cleanup, and helper socket placement.
  • Run the full Linux suite, Ruff, ty, and Sphinx with warnings treated as errors.

why: Synchronous tests need real terminal input and geometry alongside
     ordinary subprocess calls.

what:
- Add interactive and one-shot POSIX PTY and ConPTY launchers
- Separate child exit from terminal EOF and bounded capture
- Cover live input, late descendant output and timeout cleanup
tony added 4 commits December 2, 2026 20:43
why: Darwin revokes a controlling terminal when its session leader exits,
including descriptors still open in the command’s descendants.

what:
- Keep the macOS session leader alive while terminal users remain.
- Report the requested command’s PID and exit status independently.
- Check foreground input, status, native EOF, and owner shutdown.
why: The Darwin helper module must be importable on hosts without Unix
     socket support.

what:
- Open the Unix control socket only in the Darwin session path
why: Synchronous callers need the terminal helper to respect their
     temporary directory and close on startup failure.

what:
- Use the process temporary directory for the Darwin helper socket
- Check startup failure handling and record the native socket path limit
- Document the synchronous API in the public ownership guide
why: Record the branch's user-visible change in the unreleased notes.

what:
- Add the #142 entry under What's new in CHANGES
@tony
tony force-pushed the concept/terminal-subprocess branch from d933bf1 to 19200f7 Compare December 3, 2026 02:55

This branch was successfully deployed

1 active deployment
docs — 19200f7e Deployed Dec 3, 2026 by tony via build (3.14) #297
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Offer typed terminal control alongside ordinary subprocess calls

1 participant