Core LibrarystableTopics

Choose documentation 3

stable

Current version

stable
English

Prerelease This site documents an alpha of libtmux. Its structure, URLs and APIs are subject to change.

Edit this page on GitHub

Ownership and cleanup

A tmux session, window, or pane normally remains until you kill it. Scope-based cleanup can kill it when your code leaves a block, including after an exception. See Workspaces for a temporary layout example.

Nested context managers

Python’s Server, Session, Window, and Pane support context managers. Entry returns the existing object; exit kills it, including when the block raises:

with Server() as server:
with server.new_session() as session:
with session.new_window() as window:
with window.split() as pane:
pane.send_keys('echo "Hello"')
# everything above is killed on the way out, in reverse order

Nested scopes exit in reverse order: pane, window, session, then server.

Testing cleanup

Use explicit cleanup for objects whose handles have no disposal hook. For an entire disposable test server, prefer your port’s test fixture or server guard; see Testing with libtmux.

Esc

Type to search.

Reference preview Open reference