connect().
Use async
AsyncPtyHandle is the same surface with await and an async context manager.
Call the handle
Read what the handle stored
wait_for_connectionmeans the stream was opened. A short command can finish before you call it, and that still returns true. Useis_connectedto see if the stream is open at this instant.wait_for_connectionconnects for you only if you never calledconnect(). It does not re-attach a stream that has already finished, so buffered output is not duplicated.- The output buffer stops at 1 MiB. Once full, the oldest bytes are dropped. For a full transcript, pass an
on_datacallback, or redirect the program’s output to a file in the runtime. - Disconnecting leaves the shell and its scrollback running. Call
kill()to stop it. You can attach again later with a new handle. - The context manager disconnects on exit, including on exception.
From the CLI
The CLI calls the same session endpoints.pty attach owns the stream while it is open. Ctrl-C detaches and the shell keeps running.