From 922bed05a78893afb726b3ca592190cc1fa230d4 Mon Sep 17 00:00:00 2001 From: Nicolas Sebrecht Date: Sat, 4 Jun 2016 02:23:09 +0200 Subject: [PATCH] threading: improve comments Signed-off-by: Nicolas Sebrecht --- offlineimap/folder/Base.py | 11 ++++++----- offlineimap/imapserver.py | 2 +- offlineimap/threadutil.py | 3 ++- 3 files changed, 9 insertions(+), 7 deletions(-) diff --git a/offlineimap/folder/Base.py b/offlineimap/folder/Base.py index b71396a..60cf431 100644 --- a/offlineimap/folder/Base.py +++ b/offlineimap/folder/Base.py @@ -1,5 +1,5 @@ # Base folder support -# Copyright (C) 2002-2015 John Goerzen & contributors +# Copyright (C) 2002-2016 John Goerzen & contributors # # This program is free software; you can redistribute it and/or modify # it under the terms of the GNU General Public License as published by @@ -832,7 +832,7 @@ class BaseFolder(object): except Exception as e: self.ui.error(e, exc_info()[2], msg = "Copying message %s [acc: %s]"% (uid, self.accountname)) - raise #raise on unknown errors, so we can fix those + raise # Raise on unknown errors, so we can fix those. def __syncmessagesto_copy(self, dstfolder, statusfolder): """Pass1: Copy locally existing messages not on the other side. @@ -870,13 +870,14 @@ class BaseFolder(object): continue self.ui.copyingmessage(uid, num+1, num_to_copy, self, dstfolder) - # exceptions are caught in copymessageto() + + # Exceptions are caught in copymessageto(). if self.suggeststhreads(): self.waitforthread() thread = threadutil.InstanceLimitedThread( self.getinstancelimitnamespace(), target = self.copymessageto, - name = "Copy message from %s:%s" % (self.repository, self), + name = "Copy message from %s:%s"% (self.repository, self), args = (uid, dstfolder, statusfolder) ) thread.start() @@ -884,7 +885,7 @@ class BaseFolder(object): else: self.copymessageto(uid, dstfolder, statusfolder, register=0) for thread in threads: - thread.join() + thread.join() # Block until all "copy" threads are done. # Execute new mail hook if we have new mail. if self.have_newmail: diff --git a/offlineimap/imapserver.py b/offlineimap/imapserver.py index 74630ad..f373326 100644 --- a/offlineimap/imapserver.py +++ b/offlineimap/imapserver.py @@ -621,7 +621,7 @@ class IMAPServer(object): It's OK if we have maxconnections + 1 or 2 threads, which is what this will help us do.""" - self.semaphore.acquire() + self.semaphore.acquire() # Blocking until maxconnections has free slots. self.semaphore.release() def close(self): diff --git a/offlineimap/threadutil.py b/offlineimap/threadutil.py index 2e80595..d5d08f8 100644 --- a/offlineimap/threadutil.py +++ b/offlineimap/threadutil.py @@ -1,4 +1,4 @@ -# Copyright (C) 2002-2012 John Goerzen & contributors +# Copyright (C) 2002-2016 John Goerzen & contributors # Thread support module # # This program is free software; you can redistribute it and/or modify @@ -243,6 +243,7 @@ class InstanceLimitedThread(ExitNotifyThread): def start(self): global limitedNamespaces + # Will block until the semaphore has free slots. limitedNamespaces[self.limitNamespace].acquire() ExitNotifyThread.start(self)