Skip to content
This repository was archived by the owner on Mar 10, 2024. It is now read-only.

Commit a7ef17a

Browse files
authored
shut down gracefully on SIGTERM. (#1)
1 parent 92f5717 commit a7ef17a

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
@@ -7,6 +7,7 @@
77
import asyncio
88
import logging
99
import json
10+
import signal
1011
from . import settings
1112
from .app_state import AppState
1213
from .util.exceptions import LicensingError
@@ -398,4 +399,16 @@ def main():
398399
runner, host=app["settings"]["host_interface"], port=app["settings"]["app_port"]
399400
)
400401
loop.run_until_complete(site.start())
402+
403+
loop.add_signal_handler(signal.SIGTERM, lambda: loop.stop())
401404
loop.run_forever()
405+
406+
async def shutdown():
407+
logger.info("Shutting down MATLAB proxy-app")
408+
await app.shutdown()
409+
await app.cleanup()
410+
# waiting here to allow matlab to finish exiting.
411+
await asyncio.sleep(5)
412+
413+
loop.run_until_complete(shutdown())
414+

0 commit comments

Comments
 (0)