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 <Sebastian@SSpaeth.de>
This commit is contained in:
Sebastian Spaeth 2012-02-05 12:34:27 +01:00
parent ba3a698a67
commit 03566b2037
3 changed files with 6 additions and 9 deletions

View File

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

View File

@ -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()

View File

@ -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