Browse Source

Handle all keyboard interrupts more completely

Also handle abruptly closed pipe gracefully.
Steven Myint 10 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,6 +24,7 @@ if sys.hexversion < 0x02050000:
24 24
     raise SystemExit("*** Requires python >= 2.5.0")    # pragma: no cover
25 25
 
26 26
 import re
27
+import signal
27 28
 import subprocess
28 29
 import errno
29 30
 import fcntl
@@ -600,11 +601,8 @@ def markup_to_pager(stream, opts):
600 601
     # Args stolen from git source: github.com/git/git/blob/master/pager.c
601 602
     pager = subprocess.Popen(
602 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 607
     pager.stdin.close()
610 608
     pager.wait()
@@ -644,6 +642,9 @@ def decode(line):
644 642
 
645 643
 
646 644
 def main():
645
+    signal.signal(signal.SIGPIPE, signal.SIG_DFL)
646
+    signal.signal(signal.SIGINT, signal.SIG_DFL)
647
+
647 648
     from optparse import (OptionParser, BadOptionError, AmbiguousOptionError,
648 649
                           OptionGroup)
649 650