@@ -166,10 +166,7 @@ def start_executor(
166166 stdin = subprocess .PIPE ,
167167 text = True )
168168
169- # Handle ctrl-c
170- signal .signal (signal .SIGINT , lambda sig , frame : handle_sig_int (executor_proc ))
171- # Handle docker stop
172- signal .signal (signal .SIGTERM , lambda sig , frame : handle_sig_term (executor_proc ))
169+ add_signal_handlers (executor_proc )
173170 return executor_proc
174171
175172
@@ -193,22 +190,23 @@ def find_java_executor_jar(descriptor: Descriptor, mpf_home: Path) -> Path:
193190 return expanded_executor_path
194191
195192
196- def handle_sig_term (executor_proc : subprocess .Popen [str ]):
197- print (f'Sending SIGTERM({ signal .SIGTERM } ) to component executor.' )
198- executor_proc .terminate ()
199- try :
200- executor_proc .wait (1 )
201- except subprocess .TimeoutExpired :
202- executor_proc .kill ()
193+ def add_signal_handlers (executor_proc : subprocess .Popen [str ]):
194+ previously_received_signal = False
203195
196+ def handler (signal_num : int , __ ):
197+ nonlocal previously_received_signal
198+ if previously_received_signal :
199+ sys .exit (128 + signal_num )
200+ else :
201+ previously_received_signal = True
202+ sig_name = signal .Signals (signal_num ).name
203+ print (f'Sending { sig_name } ({ signal_num } ) to component executor.' )
204+ executor_proc .send_signal (signal_num )
204205
205- def handle_sig_int (executor_proc : subprocess .Popen [str ]):
206- print (f'Sending SIGINT({ signal .SIGINT } ) to component executor.' )
207- executor_proc .send_signal (signal .SIGINT )
208- try :
209- executor_proc .wait (1 )
210- except subprocess .TimeoutExpired :
211- handle_sig_term (executor_proc )
206+ # Handle ctrl-c
207+ signal .signal (signal .SIGINT , handler )
208+ # Handle docker stop
209+ signal .signal (signal .SIGTERM , handler )
212210
213211
214212def tail_log_if_needed (log_dir : Path , component_log_name : Optional [str ], executor_pid : int
0 commit comments