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

shut down gracefully on SIGTERM. #1

Merged
merged 2 commits into from
Mar 2, 2021
Merged
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)

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is this required? looks like the app cleanup is waiting for the MATLAB process to exist

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think so. i tried several times and in few cases matlab did not completed the exit and I got locked out of the matworks account for about half an hour. I will verify again.

Copy link
Collaborator Author

@shay-k shay-k Mar 2, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

verified. without this delay matlab is not finishing properly and the user is locked out.


loop.run_until_complete(shutdown())