873
|
1 #!/usr/bin/env python
|
|
2
|
|
3 """
|
|
4 wait for a process writing to stdout to keep an
|
|
5 (e.g.) ssh connection alive
|
|
6 """
|
|
7
|
|
8 import subprocess
|
|
9 import sys
|
|
10 import time
|
|
11
|
|
12 KEEPALIVE = 300 # s
|
|
13 SLEEP = 1
|
|
14
|
|
15
|
|
16 def main(args=sys.argv[1:]):
|
|
17 """CLI"""
|
|
18
|
|
19 last = start = time.time()
|
|
20 proc = subprocess.Popen(args)
|
|
21
|
|
22 while proc.poll() is None:
|
|
23 if time.time() - last > KEEPALIVE:
|
|
24 last = time.time()
|
|
25 print ("[{} s] waiting for process: {}".format(last-start, subprocess.list2cmdline(args)))
|
|
26 sys.stdout.flush()
|
|
27 exit(proc.poll())
|
|
28
|
|
29 if __name__ == '__main__':
|
|
30 main()
|