[PATCH] Fix the broken thread debugging

Sebastian Spaeth Sebastian at SSpaeth.de
Thu May 5 08:19:44 UTC 2011


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 <Sebastian at SSpaeth.de>
---
I am for putting this into master as it fixes a pretty nasty crasher that we currently experience as reported in mail id:"AANLkTi=ymCDOTDBUsOMBeX_720pvY+UrzM0t-+M+auEr at mail.gmail.com" by Alexander Skwar.

 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:
-- 
1.7.4.1




More information about the OfflineIMAP-project mailing list