Browse Source

Handle all keyboard interrupts more completely

Also handle abruptly closed pipe gracefully.
Steven Myint 11 years ago
parent
commit
2cb541c957
1 changed files with 6 additions and 5 deletions
  1. 6
    5
      cdiff.py

+ 6
- 5
cdiff.py View File

24
     raise SystemExit("*** Requires python >= 2.5.0")    # pragma: no cover
24
     raise SystemExit("*** Requires python >= 2.5.0")    # pragma: no cover
25
 
25
 
26
 import re
26
 import re
27
+import signal
27
 import subprocess
28
 import subprocess
28
 import errno
29
 import errno
29
 import fcntl
30
 import fcntl
600
     # Args stolen from git source: github.com/git/git/blob/master/pager.c
601
     # Args stolen from git source: github.com/git/git/blob/master/pager.c
601
     pager = subprocess.Popen(
602
     pager = subprocess.Popen(
602
         ['less', '-FRSX'], stdin=subprocess.PIPE, stdout=sys.stdout)
603
         ['less', '-FRSX'], stdin=subprocess.PIPE, stdout=sys.stdout)
603
-    try:
604
-        for line in color_diff:
605
-            pager.stdin.write(line.encode('utf-8'))
606
-    except KeyboardInterrupt:
607
-        pass
604
+    for line in color_diff:
605
+        pager.stdin.write(line.encode('utf-8'))
608
 
606
 
609
     pager.stdin.close()
607
     pager.stdin.close()
610
     pager.wait()
608
     pager.wait()
644
 
642
 
645
 
643
 
646
 def main():
644
 def main():
645
+    signal.signal(signal.SIGPIPE, signal.SIG_DFL)
646
+    signal.signal(signal.SIGINT, signal.SIG_DFL)
647
+
647
     from optparse import (OptionParser, BadOptionError, AmbiguousOptionError,
648
     from optparse import (OptionParser, BadOptionError, AmbiguousOptionError,
648
                           OptionGroup)
649
                           OptionGroup)
649
 
650