From 5c7d7ee44565c1e4ad8febc54b6d797df71ad183 Mon Sep 17 00:00:00 2001 From: Sebastian Spaeth Date: Wed, 4 May 2011 19:44:01 +0200 Subject: [PATCH 1/3] Output more detailed error on corrupt LocalStatus When our LocalStatus cache is corrupt, ie e.g. it contains lines not in the form number:number, we would previously just raise a ValueError stating things like "too many values". In case we encounter clearly corrupt LocalStatus cache entries, clearly raise an exception stating the filename and the line, so that people can attempt to repair it. Signed-off-by: Sebastian Spaeth Signed-off-by: Nicolas Sebrecht --- offlineimap/folder/LocalStatus.py | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/offlineimap/folder/LocalStatus.py b/offlineimap/folder/LocalStatus.py index 623829a..21cc571 100644 --- a/offlineimap/folder/LocalStatus.py +++ b/offlineimap/folder/LocalStatus.py @@ -78,8 +78,13 @@ class LocalStatusFolder(BaseFolder): assert(line == magicline) for line in file.xreadlines(): line = line.strip() - uid, flags = line.split(':') - uid = long(uid) + try: + uid, flags = line.split(':') + uid = long(uid) + except ValueError, e: + errstr = "Corrupt line '%s' in cache file '%s'" % (line, self.filename) + self.ui.warn(errstr) + raise ValueError(errstr) flags = [x for x in flags] self.messagelist[uid] = {'uid': uid, 'flags': flags} file.close() From deab62fbd84c003c5dacdf829faa1a89b9e74e9e Mon Sep 17 00:00:00 2001 From: Sebastian Spaeth Date: Thu, 5 May 2011 10:19:44 +0200 Subject: [PATCH 2/3] Fix the broken thread debugging Using threading._VERBOSE=1 is broken since python 2.6 till at least python 3.2, (http://bugs.python.org/issue4188) so we can't use it for our thread debugging. Remove the usage of threading._VERBOSE, and implement a "light thread debug log" that for now outputs information when a new thread is being registered and when it is being unregistered. I am sure we will be able to add more thread debugging information over the time. Besides '-d thread' this will re-enable the usage of -d 'all' for the most verbose debugging of all categories. Signed-off-by: Sebastian Spaeth Signed-off-by: Nicolas Sebrecht --- Changelog.draft.rst | 1 + offlineimap/init.py | 2 -- offlineimap/ui/UIBase.py | 3 +++ 3 files changed, 4 insertions(+), 2 deletions(-) diff --git a/Changelog.draft.rst b/Changelog.draft.rst index 2b109a3..eacfea1 100644 --- a/Changelog.draft.rst +++ b/Changelog.draft.rst @@ -21,6 +21,7 @@ Changes Bug Fixes --------- +* Fix the offlineimap crash when invoking debug option 'thread' Pending for the next major release ================================== diff --git a/offlineimap/init.py b/offlineimap/init.py index 296b84b..287bbbf 100644 --- a/offlineimap/init.py +++ b/offlineimap/init.py @@ -226,8 +226,6 @@ class OfflineImap: ui.add_debug(type) if type.lower() == 'imap': imaplib.Debug = 5 - if type.lower() == 'thread': - threading._VERBOSE = 1 if options.runonce: # FIXME: maybe need a better diff --git a/offlineimap/ui/UIBase.py b/offlineimap/ui/UIBase.py index 02593e6..a1cc864 100644 --- a/offlineimap/ui/UIBase.py +++ b/offlineimap/ui/UIBase.py @@ -89,11 +89,14 @@ class UIBase: (threading.currentThread().getName(), s.getthreadaccount(s), account) s.threadaccounts[threading.currentThread()] = account + s.debug('thread', "Register new thread '%s' (account '%s')" %\ + (threading.currentThread().getName(), account)) def unregisterthread(s, thr): """Recognizes a thread has exited.""" if s.threadaccounts.has_key(thr): del s.threadaccounts[thr] + s.debug('thread', "Unregister thread '%s'" % thr.getName()) def getthreadaccount(s, thr = None): if not thr: From f2ad4bc230ef70dfea0cd1c381d316dd83f0c038 Mon Sep 17 00:00:00 2001 From: Sebastian Spaeth Date: Thu, 5 May 2011 11:15:51 +0200 Subject: [PATCH 3/3] Fix typo to force singlethreading in debug mode A typo prevented us from enforcing singlethreading mode when selecting debugging. Signed-off-by: Sebastian Spaeth Signed-off-by: Nicolas Sebrecht --- offlineimap/init.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/offlineimap/init.py b/offlineimap/init.py index 287bbbf..0aaa06e 100644 --- a/offlineimap/init.py +++ b/offlineimap/init.py @@ -219,7 +219,7 @@ class OfflineImap: if not ('thread' in options.debugtype.split(',') \ and options.singlethreading): ui._msg("Debug mode: Forcing to singlethreaded.") - options.singlethreaded = True + options.singlethreading = True for type in options.debugtype.split(','): type = type.strip()