forked from diux-dev/cluster
-
Notifications
You must be signed in to change notification settings - Fork 0
/
terminate_tmux
executable file
·53 lines (46 loc) · 1.31 KB
/
terminate_tmux
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
#!/usr/bin/env python
"""
Script to clean-up tmux sessions
"""
import boto3
import time
import sys
import os
def run_shell(cmd):
"""Runs shell command, returns list of outputted lines
with newlines stripped"""
# print(cmd)
p = Popen(cmd, shell=True, stdout=PIPE, stderr=STDOUT)
(stdout, stderr) = p.communicate()
lines = stdout.split('\n')
stripped_lines = []
for l in lines:
stripped_line = l.strip()
if l:
stripped_lines.append(stripped_line)
return stripped_lines
from subprocess import PIPE, STDOUT, Popen
def run_shell(cmd):
"""Runs shell command, returns list of outputted lines
with newlines stripped"""
# print(cmd)
p = Popen(cmd, shell=True, stdout=PIPE, stderr=STDOUT)
(stdout, stderr) = p.communicate()
stdout = stdout.decode('ascii')
lines = stdout.split('\n')
stripped_lines = []
for l in lines:
stripped_line = l.strip()
if l:
stripped_lines.append(stripped_line)
return stripped_lines
def main():
for line in run_shell('tmux ls'):
session_name = line.split(':', 1)[0]
if session_name == 'tensorboard' or session_name == 'jupyter' or session_name == 'dropbox':
print("Skipping "+session_name)
continue
print("Killing "+session_name)
run_shell('tmux kill-session -t ' + session_name)
if __name__=='__main__':
main()