File tree Expand file tree Collapse file tree 1 file changed +27
-0
lines changed Expand file tree Collapse file tree 1 file changed +27
-0
lines changed Original file line number Diff line number Diff line change 66"""
77import logging
88import os
9+ import shutil
10+ import subprocess
911import typing as t
1012
1113from libtmux .common import tmux_cmd
@@ -115,6 +117,31 @@ def __init__(
115117 if colors :
116118 self .colors = colors
117119
120+ def is_alive (self ) -> bool :
121+ try :
122+ res = self .cmd ("list-sessions" )
123+ print (f"returncode: { res .returncode } " )
124+ print (f"stdout: { res .stdout } " )
125+ print (f"stderr: { res .stderr } " )
126+ return res .returncode == 0
127+ except Exception :
128+ return False
129+
130+ def raise_if_dead (self ) -> None :
131+ tmux_bin = shutil .which ("tmux" )
132+ if tmux_bin is None :
133+ raise exc .TmuxCommandNotFound ()
134+
135+ cmd_args : t .List [str ] = ["list-sessions" ]
136+ if self .socket_name :
137+ cmd_args .insert (0 , f"-L{ self .socket_name } " )
138+ if self .socket_path :
139+ cmd_args .insert (0 , f"-S{ self .socket_path } " )
140+ if self .config_file :
141+ cmd_args .insert (0 , f"-f{ self .config_file } " )
142+
143+ subprocess .check_call ([tmux_bin ] + cmd_args )
144+
118145 def cmd (self , * args : t .Any , ** kwargs : t .Any ) -> tmux_cmd :
119146 """
120147 Execute tmux command and return output.
You can’t perform that action at this time.
0 commit comments