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():
393
393
return app
394
394
395
395
396
+ def get_supported_termination_signals ():
397
+ return [signal .SIGHUP , signal .SIGINT , signal .SIGQUIT , signal .SIGTERM ]
398
+
399
+
396
400
def main ():
397
401
398
402
logger = mw_logger .get (init = True )
@@ -408,8 +412,12 @@ def main():
408
412
runner , host = app ["settings" ]["host_interface" ], port = app ["settings" ]["app_port" ]
409
413
)
410
414
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
+
413
421
loop .run_forever ()
414
422
415
423
async def shutdown ():
@@ -420,4 +428,3 @@ async def shutdown():
420
428
await asyncio .sleep (5 )
421
429
422
430
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):
452
452
xvfb .terminate ()
453
453
waiters .append (xvfb .wait ())
454
454
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
+
455
466
# Wait for termination
456
467
for waiter in waiters :
457
468
await waiter
You can’t perform that action at this time.
0 commit comments