Avoid exiting in streaming workunit reporter session #8945
Merged
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.
Problem
We were previously calling
_maybe_handle_help
within thewith
context provided by the streaming workunit handler._maybe_handle_help
checks to see if the user is trying to invoke./pants goals
and if so prints top-level goal help and calls_exiter
, which callssys.exit
. This means that we were exiting the program within thewith
-context when the user ran./pants goals
, which meant that thewith
-context wasn't doing its job of shutting down the thread that polled for workunit information. So, if the user ran./pants goals
the program wouldn't cleanly exit but the workunit polling thread would stick around looping forever.Solution
Have
_maybe_handle_help
return a signal value rather than directly calling the exit function, and check for that signal value outside thewith
-context to determine if we even need to enter it. Also refactor some of the code that was in thewith
-context to make debugging a bit easier in the future.