Skip to content

Commit ad2ef49

Browse files
committed
docs(control-mode-code): Clarify exceptions, queue semantics, env test notes
1 parent b817c41 commit ad2ef49

File tree

4 files changed

+31
-7
lines changed

4 files changed

+31
-7
lines changed

src/libtmux/_internal/engines/control_mode.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,11 @@ class ControlModeEngine(Engine):
3333
3434
By default, creates an internal session for connection management.
3535
This session is hidden from user-facing APIs like Server.sessions.
36+
37+
Commands raise :class:`~libtmux.exc.ControlModeTimeout` or
38+
:class:`~libtmux.exc.ControlModeConnectionError` on stalls/disconnects; a
39+
bounded notification queue (default 4096) records out-of-band events with
40+
drop counting when consumers fall behind.
3641
"""
3742

3843
def __init__(

src/libtmux/_internal/engines/control_protocol.py

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -159,7 +159,13 @@ def _parse_notification(line: str, parts: list[str]) -> Notification:
159159

160160

161161
class ControlProtocol:
162-
"""Parse the tmux control-mode stream into commands and notifications."""
162+
"""Parse the tmux control-mode stream into commands and notifications.
163+
164+
Maintains a FIFO queue of pending :class:`CommandContext` objects that are
165+
matched to `%begin/%end/%error` blocks, plus a bounded notification queue
166+
(default 4096) for out-of-band events. When the queue is full, additional
167+
notifications are dropped and counted so callers can detect backpressure.
168+
"""
163169

164170
def __init__(self, *, notification_queue_size: int = 4096) -> None:
165171
self.state = ParserState.IDLE

src/libtmux/exc.py

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -93,19 +93,28 @@ class WaitTimeout(LibTmuxException):
9393

9494

9595
class ControlModeTimeout(LibTmuxException):
96-
"""tmux control mode command did not return within the timeout."""
96+
"""tmux control-mode command did not return before the configured timeout.
97+
98+
Raised by :class:`~libtmux._internal.engines.control_mode.ControlModeEngine`
99+
when a command block fails to finish. The engine will close and restart the
100+
control client after emitting this error.
101+
"""
97102

98103

99104
class ControlModeProtocolError(LibTmuxException):
100-
"""Protocol-level error while parsing control mode stream."""
105+
"""Protocol-level error while parsing the control-mode stream.
106+
107+
Indicates malformed `%begin/%end/%error` framing or an unexpected parser
108+
state. The control client is marked dead and must be restarted.
109+
"""
101110

102111

103112
class ControlModeConnectionError(LibTmuxException):
104-
"""Control mode connection was lost unexpectedly."""
113+
"""Control-mode connection was lost unexpectedly (EOF/broken pipe)."""
105114

106115

107116
class SubprocessTimeout(LibTmuxException):
108-
"""tmux subprocess exceeded the allowed timeout."""
117+
"""tmux subprocess exceeded the allowed timeout for the invoked command."""
109118

110119

111120
class VariableUnpackingError(LibTmuxException):

tests/test_control_mode_regressions.py

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -218,7 +218,11 @@ class EnvPropagationFixture(t.NamedTuple):
218218

219219
@pytest.mark.parametrize("case", ENV_PROP_CASES)
220220
def test_environment_propagation(case: EnvPropagationFixture) -> None:
221-
"""Environment variables should be visible inside panes."""
221+
"""Environment vars should surface inside panes (tmux >= 3.2 for -e support).
222+
223+
Uses ``wait_for_line`` to allow control-mode capture to observe the shell
224+
output after send-keys; older tmux releases ignore ``-e`` and are skipped.
225+
"""
222226
if has_lt_version("3.2"):
223227
pytest.skip("tmux < 3.2 ignores -e in this environment")
224228

@@ -510,7 +514,7 @@ class EnvMultiFixture(t.NamedTuple):
510514

511515
@pytest.mark.parametrize("case", ENV_MULTI_CASES)
512516
def test_environment_multi_var_propagation(case: EnvMultiFixture) -> None:
513-
"""Multiple -e flags should all be delivered inside the pane."""
517+
"""Multiple ``-e`` flags should all be delivered inside the pane (tmux >= 3.2)."""
514518
if has_lt_version("3.2"):
515519
pytest.skip("tmux < 3.2 ignores -e in this environment")
516520

0 commit comments

Comments
 (0)