Skip to main content
The raw stream endpoint is a one-shot iterator: you attach, you consume, and if you want to know what was printed you accumulate it yourself. A handle wraps that into a stateful object that owns the connection for you. A handle reads the stream on a background thread (or asyncio task), buffers the output, records the exit code, and lets you ask “is it connected yet?” and “has it finished?” without writing that bookkeeping in your own code. It is the natural shape for driving an interactive program: start it, wait for the prompt, send input, wait for exit.
Creating a handle performs no I/O. Nothing is sent until you call connect().

Async

AsyncPtyHandle mirrors the same surface with await and an async context manager.

Methods

Properties

Behaviour notes

  • wait_for_connection means “was opened”, not “still open”. A short-lived command can open, produce output and finish before you call it; that still returns True. Use is_connected when you specifically need to know whether the stream is open at this instant.
  • wait_for_connection auto-connects only once. If you never called connect() it connects for you. It will not silently re-attach a stream that has already finished, so buffered output is never duplicated.
  • The output buffer is bounded at 1 MiB. Once full, the oldest bytes are dropped. For a complete transcript, pass an on_data callback and write the chunks yourself, or redirect the program’s output to a file in the runtime.
  • Disconnecting does not kill the session. The guest session and its scrollback survive, so you can re-attach later with a fresh handle. Call kill() to terminate it.
  • The context manager disconnects on exit, including on exception, so a handle cannot leak a reader thread or an open HTTP response.