Skip to content

shut down gracefully on SIGTERM. (#1) #1

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 13 additions & 0 deletions jupyter_matlab_proxy/app.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
import asyncio
import logging
import json
import signal
from . import settings
from .app_state import AppState
from .util.exceptions import LicensingError
Expand Down Expand Up @@ -398,4 +399,16 @@ def main():
runner, host=app["settings"]["host_interface"], port=app["settings"]["app_port"]
)
loop.run_until_complete(site.start())

loop.add_signal_handler(signal.SIGTERM, lambda: loop.stop())
loop.run_forever()

async def shutdown():
logger.info("Shutting down MATLAB proxy-app")
await app.shutdown()
await app.cleanup()
# waiting here to allow matlab to finish exiting.
await asyncio.sleep(5)

loop.run_until_complete(shutdown())