Refine the timing to raise EVENT_CLI_POST_EXECUTE event and catch SystemExit #199
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
What this PR do:
finallystatement to let application be aware of the final existing event and be able to register callbacks to do something.Originally inspired from the logging control flow of CLI __main__.py:
The step to close log and the step to open log is not peer to peer.
The timing to open and write log is when event EVENT_INVOKER_PRE_CMD_TBL_CREATE is raises which is inside
execut()of AzCliCommandInvoker. But the close step is outside of that method.I want to register the closing file logger callback when event EVENT_CLI_POST_EXECUTE is raised.
Such that, I can safely to close the opened fds without any leaks.
So, I moved the timing to raise EVENT_CLI_POST_EXECUTE to finally statement.
Actually, it should be the right thing to do to make the event machenism integrated.
With changing like that, CLI is able to do opening and closing thing in one uniform logic section which is to leverage the whole knack framework.
Test Guide:
With this patch in Azure/azure-cli, install in editable mode, and run:
pytest -x -v --log-level=WARN {TESTS}.