From 03566b203723655daff1e3cd6d6ba378e5f41eae Mon Sep 17 00:00:00 2001 From: Sebastian Spaeth Date: Sun, 5 Feb 2012 12:34:27 +0100 Subject: [PATCH] Replace thread.get_ident() Replace low-level thread.get_ident() with threading.currentThread().ident. This works both in python2.6 and python3. (thread is renamed _thread and its direct use is not recommended) Signed-off-by: Sebastian Spaeth --- offlineimap/imapserver.py | 8 ++++---- offlineimap/threadutil.py | 6 ++---- offlineimap/ui/Curses.py | 1 - 3 files changed, 6 insertions(+), 9 deletions(-) diff --git a/offlineimap/imapserver.py b/offlineimap/imapserver.py index 16d0cac..22c5c16 100644 --- a/offlineimap/imapserver.py +++ b/offlineimap/imapserver.py @@ -18,7 +18,6 @@ from offlineimap import imaplibutil, imaputil, threadutil, OfflineImapError from offlineimap.ui import getglobalui from threading import Lock, BoundedSemaphore, Thread, Event, currentThread -from thread import get_ident # python < 2.6 support import offlineimap.accounts import hmac import socket @@ -167,6 +166,7 @@ class IMAPServer: self.semaphore.acquire() self.connectionlock.acquire() + curThread = currentThread() imapobj = None if len(self.availableconnections): # One is available. @@ -176,7 +176,7 @@ class IMAPServer: imapobj = None for i in range(len(self.availableconnections) - 1, -1, -1): tryobj = self.availableconnections[i] - if self.lastowner[tryobj] == get_ident(): + if self.lastowner[tryobj] == curThread.ident: imapobj = tryobj del(self.availableconnections[i]) break @@ -184,7 +184,7 @@ class IMAPServer: imapobj = self.availableconnections[0] del(self.availableconnections[0]) self.assignedconnections.append(imapobj) - self.lastowner[imapobj] = get_ident() + self.lastowner[imapobj] = curThread.ident self.connectionlock.release() return imapobj @@ -297,7 +297,7 @@ class IMAPServer: self.connectionlock.acquire() self.assignedconnections.append(imapobj) - self.lastowner[imapobj] = get_ident() + self.lastowner[imapobj] = curThread.ident self.connectionlock.release() return imapobj except Exception as e: diff --git a/offlineimap/threadutil.py b/offlineimap/threadutil.py index 92c54e2..054fa11 100644 --- a/offlineimap/threadutil.py +++ b/offlineimap/threadutil.py @@ -15,13 +15,12 @@ # along with this program; if not, write to the Free Software # Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA -from threading import Lock, Thread, BoundedSemaphore +from threading import Lock, Thread, BoundedSemaphore, currentThread try: from Queue import Queue, Empty except ImportError: # python3 from queue import Queue, Empty import traceback -from thread import get_ident # python < 2.6 support import os.path import sys from offlineimap.ui import getglobalui @@ -152,7 +151,6 @@ class ExitNotifyThread(Thread): def run(self): global exitthreads - self.threadid = get_ident() try: if not ExitNotifyThread.profiledir: # normal case Thread.run(self) @@ -167,7 +165,7 @@ class ExitNotifyThread(Thread): except SystemExit: pass prof.dump_stats(os.path.join(ExitNotifyThread.profiledir, - "%s_%s.prof" % (self.threadid, self.getName()))) + "%s_%s.prof" % (self.ident, self.getName()))) except Exception as e: # Thread exited with Exception, store it tb = traceback.format_exc() diff --git a/offlineimap/ui/Curses.py b/offlineimap/ui/Curses.py index af41d35..365be60 100644 --- a/offlineimap/ui/Curses.py +++ b/offlineimap/ui/Curses.py @@ -16,7 +16,6 @@ # Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA from threading import RLock, currentThread, Lock, Event -from thread import get_ident # python < 2.6 support from collections import deque import time import sys