Skip to content

Warn with FutureWarning before __exit__ preserves unowned handles #959

In review

Description

@tony

Summary

Emit a FutureWarning when a looked-up or reused Session, Window, or Pane enters a with block without an explicit kill_on_exit argument, ahead of changing __exit__ to kill only handles created by that call (#925, #804).

Motivation

  • 0.69.0 (Scoping a Server no longer kills it #728) changed with Server() to preserve running servers unless kill_on_exit=True, while Session.__exit__, Window.__exit__, and Pane.__exit__ still unconditionally kill any live target on block exit (0.68.0 documented that caveat on Session.new_window(..., select_existing=True) in Session(docs[new_window]): Note Window.__exit__ on select_existing reuse #926).
  • Flipping {Session, Window, Pane}.__exit__ straight to killing only created handles protects shared sessions and windows, whereas existing test suites or cleanup scripts that wrote with server.sessions.get(...): or with session.new_window(..., select_existing=True): as a teardown block would leave sessions, windows, or panes running with no diagnostic.

Proposal

  • Stage safe handle teardown across two stacked pull requests:
    1. Deprecation PR (0.72.0): record creation provenance (handle.created, True on Server.new_session(), newly created Session.new_window(), Window.split(), Pane.split(), and Pane.new_pane(); False on looked-up, from_env(), from_*_id(), and select_existing=True reused handles) and add kill_on_exit: bool | None = None on Session, Window, and Pane. Target Session.__exit__ by session_id when available rather than prefix-matching session_name. When kill_on_exit is None and handle.created is False, emit a FutureWarning on __enter__ naming kill_on_exit=True and kill_on_exit=False while keeping current teardown behavior for one release cycle, and document the transition in MIGRATION tables and runnable examples.
    2. Enforcement PR (0.73.0, stacked on the deprecation PR): when kill_on_exit is None, kill on __exit__ only when handle.created is True, leaving looked-up and reused handles running without warning, and update the MIGRATION tables and Session.new_window(select_existing=True) documentation.

Alternatives

  • Changing {Session, Window, Pane}.__exit__ to preserve unowned handles in a single release with no warning: rejected because callers relying on with looked_up_session: for test teardown would leak tmux objects silently rather than learning to pass kill_on_exit=True or call .kill().

References

Activity

  1. added this to the 0.72.0 milestone on Dec 5, 2026
  2. added
    behavior-change
    area: lifecycle
    on Dec 5, 2026
  3. modified the milestones: 0.72.0, 0.71.0 on Dec 6, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    area: lifecyclebehavior-changeenhancement

    Type

    No type

    Projects

    • Status
      No status

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions