Skip to content

Commit 931d687

Browse files
shay-kprabhakk-mw
authored andcommitted
shut down gracefully on SIGTERM. (#1)
1 parent 9c7a17a commit 931d687

File tree

1 file changed

+13
-0
lines changed

1 file changed

+13
-0
lines changed

jupyter_matlab_proxy/app.py

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
import aiohttp
77
import asyncio
88
import json
9+
import signal
910
from . import settings
1011
from .app_state import AppState
1112
from .util import mw_logger
@@ -407,4 +408,16 @@ def main():
407408
runner, host=app["settings"]["host_interface"], port=app["settings"]["app_port"]
408409
)
409410
loop.run_until_complete(site.start())
411+
412+
loop.add_signal_handler(signal.SIGTERM, lambda: loop.stop())
410413
loop.run_forever()
414+
415+
async def shutdown():
416+
logger.info("Shutting down MATLAB proxy-app")
417+
await app.shutdown()
418+
await app.cleanup()
419+
# waiting here to allow matlab to finish exiting.
420+
await asyncio.sleep(5)
421+
422+
loop.run_until_complete(shutdown())
423+

0 commit comments

Comments
 (0)