Servers

  • Identified by socket path and socket name

  • May have >1 servers running of tmux at the same time.

  • Contain Sessions (which contain Windows, which contain Panes)

tmux initializes a server automatically on first running (e.g. executing tmux)

class libtmux.Server

Bases: EnvironmentMixin, OptionsMixin, HooksMixin

tmux(1) Server [server_manual].

When instantiated stores information on live, running tmux server.

Parameters:
  • socket_name (str, optional)

  • socket_path (str, optional)

  • config_file (str, optional)

  • colors (str, optional)

  • on_init (callable, optional)

  • socket_name_factory (callable, optional)

  • tmux_bin (str or pathlib.Path, optional)

Examples

>>> server
Server(socket_name=libtmux_test...)
>>> server.sessions
[Session($1 ...)]
>>> server.sessions[0].windows
[Window(@1 1:..., Session($1 ...))]
>>> server.sessions[0].active_window
Window(@1 1:..., Session($1 ...))
>>> server.sessions[0].active_pane
Pane(%1 Window(@1 1:..., Session($1 ...)))

The server can be used as a context manager to ensure proper cleanup:

>>> with Server() as server:
...     session = server.new_session()
...     # Do work with the session
...     # Server will be killed automatically when exiting the context

References

[server_manual]
CLIENTS AND SESSIONS. openbsd manpage for TMUX(1)

“The tmux server manages clients, sessions, windows and panes. Clients are attached to sessions to interact with them, either when they are created with the new-session command, or later with the attach-session command. Each session has one or more windows linked into it. Windows may be linked to multiple sessions and are made up of one or more panes, each of which contains a pseudo terminal.”

https://man.openbsd.org/tmux.1#CLIENTS_AND_SESSIONS. Accessed April 1st, 2018.