[Yum-devel] [PATCH 09/10] Improve ctrl-c handling

Zdeněk Pavlas zpavlas at redhat.com
Mon Nov 7 10:55:16 UTC 2011


We don't detach the downloader process from TTY, so it receives
SIGINT as well, and may even exit sooner than Python raises
KeyboardInterrupt in the parent process.

- downloader: don't print ctrl-c traceback
- parent: handle EINTR and EOF as ctrl-c
---
 urlgrabber/grabber.py |   14 +++++++++++---
 1 files changed, 11 insertions(+), 3 deletions(-)

diff --git a/urlgrabber/grabber.py b/urlgrabber/grabber.py
index 7bb2f96..cd1724c 100644
--- a/urlgrabber/grabber.py
+++ b/urlgrabber/grabber.py
@@ -455,7 +455,7 @@ import pycurl
 from ftplib import parse150
 from StringIO import StringIO
 from httplib import HTTPException
-import socket, select
+import socket, select, errno
 from byterange import range_tuple_normalize, range_tuple_to_header, RangeError
 
 try:
@@ -2087,7 +2087,13 @@ class _ExternalDownloader:
 
     def perform(self):
         ret = []
-        lines = _readlines(self.stdout)
+        try: lines = _readlines(self.stdout)
+        except OSError, e:
+            if e.args[0] != errno.EINTR: raise
+            raise KeyboardInterrupt
+        if not lines:
+            if DEBUG: DEBUG.info('downloader died')
+            raise KeyboardInterrupt
         for line in lines:
             # parse downloader output
             line = line.split(' ', 3)
@@ -2337,7 +2343,9 @@ def _test_file_object_readlines(wrapper, fo_output):
 
 if __name__ == '__main__':
     if sys.argv[1:] == ['DOWNLOADER']:
-        download_process()
+        try: download_process()
+        except KeyboardInterrupt:
+            raise SystemExit # no traceback
 
     _main_test()
     _retry_test()
-- 
1.7.4.4



More information about the Yum-devel mailing list