[PATCH 2/4] Catch KeyboardInterrupt exceptions explicitely

Sebastian Spaeth Sebastian at SSpaeth.de
Mon Jan 10 10:00:39 GMT 2011


Previously we did not catch KeyboardInterrupts explicitly as all of the
code was executed in forked child threads which would never receive
Ctrl-c exceptions. With the upcoming single threaded modus, this code
can be run in the main thread however, so we need to take care of
KeyboardInterrupts explicitly.

This was done wherever we would catch *ALL* exceptions universally and
print out an error message.

Signed-off-by: Sebastian Spaeth <Sebastian at SSpaeth.de>
---
 offlineimap/folder/Base.py        |    8 ++++++++
 offlineimap/folder/LocalStatus.py |    3 +++
 offlineimap/repository/Base.py    |    3 ++-
 3 files changed, 13 insertions(+), 1 deletions(-)

diff --git a/offlineimap/folder/Base.py b/offlineimap/folder/Base.py
index a79dcf8..edf9e2f 100644
--- a/offlineimap/folder/Base.py
+++ b/offlineimap/folder/Base.py
@@ -290,6 +290,8 @@ class BaseFolder:
                     self.savemessage(newuid, message, flags, rtime)
                     self.deletemessage(uid)
                     uid = newuid
+        except (KeyboardInterrupt):
+            raise
         except:
             self.ui.warn("ERROR attempting to copy message " + str(uid) \
                  + " for account " + self.getaccountname() + ":" + str(sys.exc_info()[1]))
@@ -395,6 +397,8 @@ class BaseFolder:
 
         try:
             self.syncmessagesto_neguid(dest, applyto)
+        except (KeyboardInterrupt):
+            raise
         except:
             self.ui.warn("ERROR attempting to handle negative uids " \
                 + "for account " + self.getaccountname() + ":" + str(sys.exc_info()[1]))
@@ -404,6 +408,8 @@ class BaseFolder:
 
         try:
             self.syncmessagesto_delete(dest, applyto)
+        except (KeyboardInterrupt):
+            raise
         except:
             self.ui.warn("ERROR attempting to delete messages " \
                 + "for account " + self.getaccountname() + ":" + str(sys.exc_info()[1]))
@@ -414,6 +420,8 @@ class BaseFolder:
 
         try:
             self.syncmessagesto_flags(dest, applyto)
+        except (KeyboardInterrupt):
+            raise
         except:
             self.ui.warn("ERROR attempting to sync flags " \
                 + "for account " + self.getaccountname() + ":" + str(sys.exc_info()[1]))
diff --git a/offlineimap/folder/LocalStatus.py b/offlineimap/folder/LocalStatus.py
index 157989d..3195886 100644
--- a/offlineimap/folder/LocalStatus.py
+++ b/offlineimap/folder/LocalStatus.py
@@ -108,7 +108,10 @@ class LocalStatusFolder(BaseFolder):
                     fd = os.open(os.path.dirname(self.filename), os.O_RDONLY)
                     os.fsync(fd)
                     os.close(fd)
+                except (KeyboardInterrupt):
+                    raise
                 except:
+                    #TODO, we should catch a specific Exception here, not ALL. But which?
                     pass
 
         finally:
diff --git a/offlineimap/repository/Base.py b/offlineimap/repository/Base.py
index 0f4dd76..cec9c61 100644
--- a/offlineimap/repository/Base.py
+++ b/offlineimap/repository/Base.py
@@ -163,10 +163,11 @@ class BaseRepository(CustomConfig.ConfigHelperMixin):
                     dest.makefolder(key)
                     for copyfolder in copyfolders:
                         copyfolder.makefolder(key.replace(dest.getsep(), copyfolder.getsep()))
+                except (KeyboardInterrupt):
+                    raise
                 except:
                     getglobalui().warn("ERROR Attempting to make folder " \
                         + key + ":"  +str(sys.exc_info()[1]))
-                
 
         #
         # Find deleted folders.
-- 
1.7.1





More information about the OfflineIMAP-project mailing list