File tree Expand file tree Collapse file tree 2 files changed +21
-3
lines changed Expand file tree Collapse file tree 2 files changed +21
-3
lines changed Original file line number Diff line number Diff line change @@ -393,6 +393,10 @@ def create_app():
393393 return app
394394
395395
396+ def get_supported_termination_signals ():
397+ return [signal .SIGHUP , signal .SIGINT , signal .SIGQUIT , signal .SIGTERM ]
398+
399+
396400def main ():
397401
398402 logger = mw_logger .get (init = True )
@@ -408,8 +412,12 @@ def main():
408412 runner , host = app ["settings" ]["host_interface" ], port = app ["settings" ]["app_port" ]
409413 )
410414 loop .run_until_complete (site .start ())
411-
412- loop .add_signal_handler (signal .SIGTERM , lambda : loop .stop ())
415+
416+ # Register handlers to trap termination signals
417+ for signal in get_supported_termination_signals ():
418+ logger .info (f"Installing handler for signal: { signal } " )
419+ loop .add_signal_handler (signal , lambda : loop .stop ())
420+
413421 loop .run_forever ()
414422
415423 async def shutdown ():
@@ -420,4 +428,3 @@ async def shutdown():
420428 await asyncio .sleep (5 )
421429
422430 loop .run_until_complete (shutdown ())
423-
Original file line number Diff line number Diff line change @@ -452,6 +452,17 @@ async def stop_matlab(self):
452452 xvfb .terminate ()
453453 waiters .append (xvfb .wait ())
454454
455+ # Clean up matlab_ready_file
456+ try :
457+ with open (self .settings ["matlab_ready_file" ], "r" ) as mrf :
458+ port_in_matlab_ready_file = mrf .read ()
459+ if str (self .matlab_port ) == port_in_matlab_ready_file :
460+ logger .info ("Cleaning up matlab_ready_file..." )
461+ self .settings ["matlab_ready_file" ].unlink ()
462+ except FileNotFoundError :
463+ # Some other process deleted this file
464+ pass
465+
455466 # Wait for termination
456467 for waiter in waiters :
457468 await waiter
You can’t perform that action at this time.
0 commit comments