Implement clean CTRL-C termination
Previously, we would simply bail out in an ugly way, potentially leaving temporary files around etc, or while writing status files. Hand SIGINT and SIGTERM as an event to the Account class, and make that bail out cleanly at predefined points. Stopping on ctrl-c can take a few seconds (it will e.g. finish to transfer the ongoing message), but it will shut down cleanly. Signed-off-by: Sebastian Spaeth <Sebastian@SSpaeth.de>
This commit is contained in:
@@ -18,6 +18,7 @@
|
||||
from offlineimap import threadutil
|
||||
from offlineimap.ui import getglobalui
|
||||
from offlineimap.error import OfflineImapError
|
||||
import offlineimap.accounts
|
||||
import os.path
|
||||
import re
|
||||
from sys import exc_info
|
||||
@@ -332,6 +333,9 @@ class BaseFolder(object):
|
||||
self.getmessageuidlist())
|
||||
num_to_copy = len(copylist)
|
||||
for num, uid in enumerate(copylist):
|
||||
# bail out on CTRL-C or SIGTERM
|
||||
if offlineimap.accounts.Account.abort_NOW_signal.is_set():
|
||||
break
|
||||
self.ui.copyingmessage(uid, num+1, num_to_copy, self, dstfolder)
|
||||
# exceptions are caught in copymessageto()
|
||||
if self.suggeststhreads():
|
||||
@@ -447,6 +451,9 @@ class BaseFolder(object):
|
||||
('syncing flags' , self.syncmessagesto_flags)]
|
||||
|
||||
for (passdesc, action) in passes:
|
||||
# bail out on CTRL-C or SIGTERM
|
||||
if offlineimap.accounts.Account.abort_NOW_signal.is_set():
|
||||
break
|
||||
try:
|
||||
action(dstfolder, statusfolder)
|
||||
except (KeyboardInterrupt):
|
||||
|
Reference in New Issue
Block a user