Lokasi ngalangkungan proxy:   [ UP ]  
[Ngawartoskeun bug]   [Panyetelan cookie]                
Skip to content

Concept: Drive terminal subprocesses from synchronous Python - #142

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

tony wants to merge 2 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.

@tony
tony force-pushed the concept/terminal-subprocess branch from e56a9c8 to d933bf1 Compare December 1, 2026 03:33
tony added a commit that referenced this pull request Dec 3, 2026
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
@tony
tony force-pushed the concept/terminal-subprocess branch from 19200f7 to 4e848c1 Compare December 3, 2026 23:58
tony added a commit that referenced this pull request Dec 5, 2026
why: Synchronous callers need to exchange input and frames with a child.

what:
- Expose the terminal subprocess context manager and its PTY adapters.
- Honor the caller's temporary directory for terminal socket setup.
- Exercise teardown and frame reads through the public API.

Adapted from #142 at 4e848c1.
@tony
tony force-pushed the concept/terminal-subprocess branch from a90f825 to 23b7f2c Compare December 5, 2026 14:56
@tony
tony force-pushed the concept/terminal-subprocess branch from 23b7f2c to dcf6243 Compare December 5, 2026 15:06
tony added 2 commits December 5, 2026 09:24
why: Reuse terminal initialization, slave PTY configuration, and
reader attachment between open_pty and the Darwin session-leader
launcher without duplicating termios or OSC 7 setup.

what:
- Extract _resolve_python_executable, _make_pty_terminal,
  _prepare_pty_fds, and _child_pty_env in libvt.aio._pty.
- Add PtySession._start_reading and call it from open_pty.
why: Synchronous tests need real PTY or ConPTY interaction, bounded
output capture, and separate child-exit vs terminal-EOF waits on top
of libvt's async sessions and recorder protocol.

what:
- Add libvt.contrib.subprocess with VT (raw_limit >= 0), Capture,
  CompletedTerminal, TerminalProcess, CalledTerminalError,
  TerminalTimeoutExpired, open_terminal, and run_terminal without
  re-exporting stdlib Popen or run.
- Resolve FlightRecorder via find_flight_recorder and implement
  SupportsVtTarget on Capture and TerminalProcess.
- Add a single-trampoline Darwin PTY session owner over
  socket.socketpair and a Win32 ConPTY backend.
- Document libvt.contrib.subprocess in docs, README, and CHANGES,
  and add cross-platform subprocess and Darwin helper tests.

Refs #106
@tony
tony force-pushed the concept/terminal-subprocess branch from dcf6243 to 6776ee2 Compare December 5, 2026 15:27

This branch was successfully deployed

1 active deployment
docs — 6776ee2a Deployed Dec 5, 2026 by tony via build (3.14) #495
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