From c0659d1a8ce9c4eb6a29a34f4bbf2b0ec2d2f83a Mon Sep 17 00:00:00 2001 From: Ian Cordasco Date: Tue, 15 Mar 2016 11:53:12 -0500 Subject: [PATCH] Catch Keyboard interruptions in our application Add logging to our main application --- flake8/main/cli.py | 18 +++++++++++++++--- 1 file changed, 15 insertions(+), 3 deletions(-) diff --git a/flake8/main/cli.py b/flake8/main/cli.py index 06299ec..ecbdde9 100644 --- a/flake8/main/cli.py +++ b/flake8/main/cli.py @@ -1,4 +1,6 @@ """Command-line implementation of flake8.""" +import logging + import flake8 from flake8 import checker from flake8 import defaults @@ -7,6 +9,8 @@ from flake8.options import aggregator from flake8.options import manager from flake8.plugins import manager as plugin_manager +LOG = logging.getLogger(__name__) + def register_default_options(option_manager): """Register the default options on our OptionManager.""" @@ -267,9 +271,7 @@ class Application(object): """Report all the errors found by flake8 3.0.""" self.file_checker_manager.report() - def run(self, argv=None): - # type: (Union[NoneType, List[str]]) -> NoneType - """Run our application.""" + def _run(self, argv): self.find_plugins() self.register_plugin_options() self.parse_configuration_and_cli(argv) @@ -280,6 +282,16 @@ class Application(object): self.run_checks() self.report_errors() + def run(self, argv=None): + # type: (Union[NoneType, List[str]]) -> NoneType + """Run our application.""" + try: + self._run(argv) + except KeyboardInterrupt as exc: + LOG.critical('Caught keyboard interrupt from user') + LOG.exception(exc) + self.file_checker_manager._force_cleanup() + def main(argv=None): # type: (Union[NoneType, List[str]]) -> NoneType