File tree 1 file changed +27
-0
lines changed
1 file changed +27
-0
lines changed Original file line number Diff line number Diff line change 6
6
"""
7
7
import logging
8
8
import os
9
+ import shutil
10
+ import subprocess
9
11
import typing as t
10
12
11
13
from libtmux .common import tmux_cmd
@@ -115,6 +117,31 @@ def __init__(
115
117
if colors :
116
118
self .colors = colors
117
119
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
+
118
145
def cmd (self , * args : t .Any , ** kwargs : t .Any ) -> tmux_cmd :
119
146
"""
120
147
Execute tmux command and return output.
You can’t perform that action at this time.
0 commit comments