@@ -107,6 +107,22 @@ def check_status():
107
107
child_process = start_bazarr ()
108
108
109
109
110
+ def is_process_running (pid ):
111
+ commands = {
112
+ "win" : ["tasklist" , "/FI" , f"PID eq { pid } " ],
113
+ "linux" : ["ps" , "-eo" , "pid" ],
114
+ "darwin" : ["ps" , "-ax" , "-o" , "pid" ]
115
+ }
116
+
117
+ # Determine OS and execute corresponding command
118
+ for key in commands :
119
+ if sys .platform .startswith (key ):
120
+ result = subprocess .run (commands [key ], capture_output = True , text = True )
121
+ return str (pid ) in result .stdout .split ()
122
+
123
+ print ("Unsupported OS" )
124
+ return False
125
+
110
126
def interrupt_handler (signum , frame ):
111
127
# catch and ignore keyboard interrupt Ctrl-C
112
128
# the child process Server object will catch SIGINT and perform an orderly shutdown
@@ -116,7 +132,9 @@ def interrupt_handler(signum, frame):
116
132
interrupted = True
117
133
print ('Handling keyboard interrupt...' )
118
134
else :
119
- print ("Stop doing that! I heard you the first time!" )
135
+ if not is_process_running (child_process ):
136
+ # this will be caught by the main loop below
137
+ raise SystemExit (EXIT_INTERRUPT )
120
138
121
139
122
140
if __name__ == '__main__' :
0 commit comments