-
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathrun.xsh
executable file
·31 lines (22 loc) · 818 Bytes
/
run.xsh
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
#!/usr/bin/env xonsh
# https://github.com/anki-code/docker-xonsh-wrapper
import subprocess, signal
from xonsh.tools import print_color
class Process:
stop_now = False
def __init__(self, cmd):
for s in [signal.SIGINT, signal.SIGTERM]:
signal.signal(s, self.proc_terminate)
proc = subprocess.Popen(cmd, shell=True)
self.proc = proc
self.pid = proc.pid
proc.wait()
def proc_terminate(self, signum, frame):
print_color(f'CATCH: signum={signum}, stopping the process...')
self.proc.terminate()
self.stop_now = True
if __name__ == '__main__':
echo '[Work before running the app]'
echo "The app just sleep 2 minutes zZzZzZz..."
p = Process('sleep 2m')
echo '[Work after running the app or getting stop signals]'