Catch SystemExit and KeyboardInterrupt exceptions

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@SSpaeth.de>
Signed-off-by: Nicolas Sebrecht <nicolas.s-dev@laposte.net>
This commit is contained in:
Sebastian Spaeth 2011-01-12 11:15:08 +01:00 committed by Nicolas Sebrecht
parent fe9e5221b2
commit 383ae9e647
2 changed files with 12 additions and 6 deletions

View File

@ -187,6 +187,8 @@ class AccountSynchronizationMixin:
try: try:
try: try:
self.sync(siglistener) self.sync(siglistener)
except (KeyboardInterrupt, SystemExit):
raise
except: except:
self.ui.warn("Error occured attempting to sync account " + self.name \ self.ui.warn("Error occured attempting to sync account " + self.name \
+ ": " + str(sys.exc_info()[1])) + ": " + str(sys.exc_info()[1]))
@ -201,6 +203,8 @@ class AccountSynchronizationMixin:
try: try:
try: try:
self.sync(siglistener) self.sync(siglistener)
except (KeyboardInterrupt, SystemExit):
raise
except: except:
self.ui.warn("Error occured attempting to sync account " + self.name \ self.ui.warn("Error occured attempting to sync account " + self.name \
+ ": " + str(sys.exc_info()[1])) + ": " + str(sys.exc_info()[1]))
@ -370,6 +374,8 @@ def syncfolder(accountname, remoterepos, remotefolder, localrepos,
localfolder.syncmessagesto(statusfolder) localfolder.syncmessagesto(statusfolder)
statusfolder.save() statusfolder.save()
localrepos.restore_atime() localrepos.restore_atime()
except (KeyboardInterrupt, SystemExit):
raise
except: except:
ui.warn("ERROR in syncfolder for %s folder %s: %s" % \ ui.warn("ERROR in syncfolder for %s folder %s: %s" % \
(accountname,remotefolder.getvisiblename(),sys.exc_info()[1])) (accountname,remotefolder.getvisiblename(),sys.exc_info()[1]))

View File

@ -334,14 +334,14 @@ class OfflineImap:
'siglisteners': siglisteners}) 'siglisteners': siglisteners})
t.setDaemon(1) t.setDaemon(1)
t.start() t.start()
threadutil.exitnotifymonitorloop(threadutil.threadexited)
except KeyboardInterrupt:
ui.terminate(1, errormsg = 'CTRL-C pressed, aborting...')
return
except (SystemExit):
raise
except: except:
ui.mainException() ui.mainException()
try:
threadutil.exitnotifymonitorloop(threadutil.threadexited)
except SystemExit:
raise
except:
ui.mainException() # Also expected to terminate.