Skip to content
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

Avoid exiting in streaming workunit reporter session #8945

Merged
merged 1 commit into from Jan 13, 2020

Conversation

gshuflin
Copy link
Contributor

Problem

We were previously calling _maybe_handle_help within the with 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 calls sys.exit. This means that we were exiting the program within the with-context when the user ran ./pants goals, which meant that the with-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 the with-context to determine if we even need to enter it. Also refactor some of the code that was in the with-context to make debugging a bit easier in the future.

@@ -257,7 +257,9 @@ def _maybe_handle_help(self):
if self._options.help_request:
help_printer = HelpPrinter(self._options)
result = help_printer.print_help()
self._exiter(result)
return result
else:
Copy link
Member

Choose a reason for hiding this comment

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

I don't think we need else: return None it is implicit.

I think what we actually need to return a is a the boolean value of self._options.help_request and not result.

def _finish_run(self):
try:
self._update_stats()
run_tracker_result = self._run_tracker.end()
Copy link
Member

Choose a reason for hiding this comment

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

for simplicity we should just do return self._run_tracker.end()
and return PANTS_SUCCEEDED_EXIT_CODE (when we catch an error).
it is less code and more pythonic.

@gshuflin gshuflin merged commit 73c6e7b into pantsbuild:master Jan 13, 2020
@gshuflin gshuflin deleted the fix_maybe_help branch January 13, 2020 19:11
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants