Improve code for waiting the accountThreads. Signed-off-by: Nicolas Sebrecht <[email protected]> ---
The following changes since commit 3293b75c9c735f054eb267afcc6f3f9713e6c1aa: release.sh: get_git_who(): remove unnecessary blank line (2016-06-27 16:11:44 +0200) are available in the git repository at: https://github.com/nicolas33/offlineimap.git ns/with for you to fetch changes up to af6679be778aec99b87dd6f809cd2e16d21eadd3: threadutil: use 'with' statements for lock (2016-06-28 02:20:12 +0200) ---------------------------------------------------------------- offlineimap/threadutil.py | 23 +++++++---------------- 1 file changed, 7 insertions(+), 16 deletions(-) diff --git a/offlineimap/threadutil.py b/offlineimap/threadutil.py index d5d08f8..29272db 100644 --- a/offlineimap/threadutil.py +++ b/offlineimap/threadutil.py @@ -50,33 +50,24 @@ class accountThreads(object): self.list = [] def add(self, thread): - self.lock.acquire() - try: + with self.lock: self.list.append(thread) - finally: - self.lock.release() def remove(self, thread): - self.lock.acquire() - try: + with self.lock: self.list.remove(thread) - finally: - self.lock.release() def pop(self): - self.lock.acquire() - try: - if not len(self.list): + with self.lock: + if len(self.list) < 1: return None return self.list.pop() - finally: - self.lock.release() def wait(self): - while 1: + while True: thread = self.pop() - if not thread: - return + if thread is None: + break thread.join() -- 2.7.4 _______________________________________________ OfflineIMAP-project mailing list: [email protected] http://lists.alioth.debian.org/cgi-bin/mailman/listinfo/offlineimap-project OfflineIMAP homepages: - https://github.com/OfflineIMAP - http://offlineimap.org
