summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorFlorent Xicluna <florent.xicluna@gmail.com>2014-04-26 16:13:48 +0200
committerFlorent Xicluna <florent.xicluna@gmail.com>2014-04-26 16:13:48 +0200
commitc3b1fc2b749cffa4d43e3e71d968a5e37a30b6f2 (patch)
treee7903b3c27cd54fb49e174a4de0a0d437df12a3c
parenta25406bc28d208400fb094aa5a82766ec6072c9c (diff)
downloadpyflakes-c3b1fc2b749cffa4d43e3e71d968a5e37a30b6f2.tar.gz
Skip the traceback on Control+C and Broken pipe signals; fixes lp:1285290
-rw-r--r--NEWS.txt3
-rw-r--r--pyflakes/api.py14
2 files changed, 15 insertions, 2 deletions
diff --git a/NEWS.txt b/NEWS.txt
index f2cb215..7e81cf7 100644
--- a/NEWS.txt
+++ b/NEWS.txt
@@ -1,3 +1,6 @@
+UNRELEASED:
+ - Skip the traceback on Control+C and "Broken pipe" signals.
+
0.8.1 (2014-03-30):
- Detect the declared encoding in Python 3.
- Do not report redefinition of import in a local scope, if the
diff --git a/pyflakes/api.py b/pyflakes/api.py
index f32881e..e8647f9 100644
--- a/pyflakes/api.py
+++ b/pyflakes/api.py
@@ -6,7 +6,6 @@ from __future__ import with_statement
import sys
import os
import _ast
-from optparse import OptionParser
from pyflakes import checker, __version__
from pyflakes import reporter as modReporter
@@ -123,7 +122,18 @@ def checkRecursive(paths, reporter):
def main(prog=None):
- parser = OptionParser(prog=prog, version=__version__)
+ """Entry point for the script "pyflakes"."""
+ import optparse
+ import signal
+
+ # Handle "Keyboard Interrupt" and "Broken pipe" gracefully
+ try:
+ signal.signal(signal.SIGINT, lambda sig, f: sys.exit('... stopped'))
+ signal.signal(signal.SIGPIPE, lambda sig, f: sys.exit(1))
+ except ValueError:
+ pass # SIGPIPE is not supported on Windows
+
+ parser = optparse.OptionParser(prog=prog, version=__version__)
(__, args) = parser.parse_args()
reporter = modReporter._makeDefaultReporter()
if args: