Handles query cancellation on a Ctrl+C event
(self, signal, frame)
| 734 | self.imp_client.close_connection() |
| 735 | |
| 736 | def _signal_handler(self, signal, frame): |
| 737 | """Handles query cancellation on a Ctrl+C event""" |
| 738 | if self.last_query_handle is None or self.last_query_handle.is_closed: |
| 739 | if self.partial_cmd: |
| 740 | # Revert the prompt to its earlier state |
| 741 | self.prompt = self.cached_prompt |
| 742 | # Reset the already given commands |
| 743 | self.partial_cmd = str() |
| 744 | raise KeyboardInterrupt() |
| 745 | # Create a new connection to the impalad and cancel the query. |
| 746 | # TODO: this isn't thread-safe with respect to the main thread executing the |
| 747 | # query. This probably contributes to glitchiness when cancelling query in |
| 748 | # the shell. |
| 749 | for cancel_try in xrange(ImpalaShell.CANCELLATION_TRIES): |
| 750 | try: |
| 751 | self.imp_client.is_query_cancelled = True |
| 752 | os.write(sys.stderr.fileno(), ImpalaShell.CANCELLATION_MESSAGE.encode('utf-8')) |
| 753 | new_imp_client = self._new_impala_client() |
| 754 | new_imp_client.connect() |
| 755 | try: |
| 756 | new_imp_client.cancel_query(self.last_query_handle) |
| 757 | new_imp_client.close_query(self.last_query_handle) |
| 758 | finally: |
| 759 | new_imp_client.close_connection() |
| 760 | break |
| 761 | except Exception as e: |
| 762 | # Suppress harmless errors. |
| 763 | err_msg = str(e).strip() |
| 764 | # Check twice so that it can work with both the old and the new error formats. |
| 765 | if err_msg in ['ERROR: Cancelled', 'ERROR: Invalid or unknown query handle'] or \ |
| 766 | ('\nCancelled' in err_msg or '\nInvalid or unknown query handle' in err_msg): |
| 767 | break |
| 768 | err_details = "Failed to reconnect and close (try {}/{}): {}".format( |
| 769 | cancel_try + 1, ImpalaShell.CANCELLATION_TRIES, err_msg) |
| 770 | os.write(sys.stderr.fileno(), err_details.encode('utf-8')) |
| 771 | |
| 772 | def _is_quit_command(self, command): |
| 773 | # Do a case insensitive check |
nothing calls this directly
no test coverage detected