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

shut down gracefully on SIGTERM. #1

merged 2 commits into from
Mar 2, 2021

Conversation

shay-k
Copy link
Collaborator

@shay-k shay-k commented Mar 1, 2021

No description provided.

@shay-k shay-k requested a review from zvikagart March 1, 2021 11:18
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.


fu = loop.create_future()
# on SIGTERM setting the future result allowing the loop to exit.
loop.add_signal_handler(signal.SIGTERM, lambda : fu.set_result(True))

Choose a reason for hiding this comment

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

nit: remove space after lambda

@@ -398,4 +399,18 @@ def main():
runner, host=app["settings"]["host_interface"], port=app["settings"]["app_port"]
)
loop.run_until_complete(site.start())
loop.run_forever()

fu = loop.create_future()

Choose a reason for hiding this comment

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

Another option is to keep the loop.run_forever(), add the signal handler before it, and then call loop.stop() from shutdown

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 must use a synchronous method for the signal handler and shutdown func must remain async so it would wait for app.shutdown() and app.cleanup().
so the lambda now calls loop.stop and then I call loop.run_until_complete(shutdown())

@shay-k
Copy link
Collaborator Author

shay-k commented Mar 2, 2021

[ch38056]

@shay-k shay-k requested a review from zvikagart March 2, 2021 11:24
@shay-k shay-k merged commit a7ef17a into main Mar 2, 2021
@shay-k shay-k deleted the handle_sigterm branch March 2, 2021 13:25
shay-k added a commit that referenced this pull request Mar 9, 2021
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants