[PATCH 1/6] Catch SystemExit and KeyboardInterrupt exceptions
Sebastian Spaeth
Sebastian at SSpaeth.de
Wed Jan 12 10:15:08 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. As this is pretty highlevel code, we also
protect against receiving a SystemExit exception which is raised e.g. in
the ui.terminate() code by calling sys.exit().
Signed-off-by: Sebastian Spaeth <Sebastian at SSpaeth.de>
---
offlineimap/accounts.py | 6 ++++++
offlineimap/init.py | 12 ++++++------
2 files changed, 12 insertions(+), 6 deletions(-)
diff --git a/offlineimap/accounts.py b/offlineimap/accounts.py
index 0fc1edf..cd09646 100644
--- a/offlineimap/accounts.py
+++ b/offlineimap/accounts.py
@@ -187,6 +187,8 @@ class AccountSynchronizationMixin:
try:
try:
self.sync(siglistener)
+ except (KeyboardInterrupt, SystemExit):
+ raise
except:
self.ui.warn("Error occured attempting to sync account " + self.name \
+ ": " + str(sys.exc_info()[1]))
@@ -201,6 +203,8 @@ class AccountSynchronizationMixin:
try:
try:
self.sync(siglistener)
+ except (KeyboardInterrupt, SystemExit):
+ raise
except:
self.ui.warn("Error occured attempting to sync account " + self.name \
+ ": " + str(sys.exc_info()[1]))
@@ -370,6 +374,8 @@ def syncfolder(accountname, remoterepos, remotefolder, localrepos,
localfolder.syncmessagesto(statusfolder)
statusfolder.save()
localrepos.restore_atime()
+ except (KeyboardInterrupt, SystemExit):
+ raise
except:
ui.warn("ERROR in syncfolder for %s folder %s: %s" % \
(accountname,remotefolder.getvisiblename(),sys.exc_info()[1]))
diff --git a/offlineimap/init.py b/offlineimap/init.py
index 670ab07..4347bf1 100644
--- a/offlineimap/init.py
+++ b/offlineimap/init.py
@@ -332,14 +332,14 @@ class OfflineImap:
'siglisteners': siglisteners})
t.setDaemon(1)
t.start()
- except:
- ui.mainException()
-
- try:
threadutil.exitnotifymonitorloop(threadutil.threadexited)
- except SystemExit:
+
+ except KeyboardInterrupt:
+ ui.terminate(1, errormsg = 'CTRL-C pressed, aborting...')
+ return
+ except (SystemExit):
raise
except:
- ui.mainException() # Also expected to terminate.
+ ui.mainException()
--
1.7.1
More information about the OfflineIMAP-project
mailing list