threadutil: explicitly import get_ident from thread
The python module thread is the low-level module we should avoid to use in favor of threading. We still need it to support old python because Thread.ident doesn't exist before python 2.6: http://docs.python.org/library/threading.html#threading.Thread.ident Make it clear we should avoid it. Reviewed-by: Sebastian Spaeth <Sebastian@SSpaeth.de> Signed-off-by: Nicolas Sebrecht <nicolas.s-dev@laposte.net>
This commit is contained in:
parent
8a34edc8ca
commit
d5493fe894
@ -19,7 +19,7 @@
|
||||
from offlineimap import imaplibutil, imaputil, threadutil, OfflineImapError
|
||||
from offlineimap.ui import getglobalui
|
||||
from threading import Lock, BoundedSemaphore
|
||||
import thread
|
||||
from thread import get_ident # python < 2.6 support
|
||||
import time
|
||||
import hmac
|
||||
import socket
|
||||
@ -167,11 +167,10 @@ class IMAPServer:
|
||||
# Try to find one that previously belonged to this thread
|
||||
# as an optimization. Start from the back since that's where
|
||||
# they're popped on.
|
||||
threadid = thread.get_ident()
|
||||
imapobj = None
|
||||
for i in range(len(self.availableconnections) - 1, -1, -1):
|
||||
tryobj = self.availableconnections[i]
|
||||
if self.lastowner[tryobj] == threadid:
|
||||
if self.lastowner[tryobj] == get_ident():
|
||||
imapobj = tryobj
|
||||
del(self.availableconnections[i])
|
||||
break
|
||||
@ -179,7 +178,7 @@ class IMAPServer:
|
||||
imapobj = self.availableconnections[0]
|
||||
del(self.availableconnections[0])
|
||||
self.assignedconnections.append(imapobj)
|
||||
self.lastowner[imapobj] = thread.get_ident()
|
||||
self.lastowner[imapobj] = get_ident()
|
||||
self.connectionlock.release()
|
||||
return imapobj
|
||||
|
||||
@ -266,7 +265,7 @@ class IMAPServer:
|
||||
|
||||
self.connectionlock.acquire()
|
||||
self.assignedconnections.append(imapobj)
|
||||
self.lastowner[imapobj] = thread.get_ident()
|
||||
self.lastowner[imapobj] = get_ident()
|
||||
self.connectionlock.release()
|
||||
return imapobj
|
||||
except Exception, e:
|
||||
|
@ -19,7 +19,7 @@
|
||||
from threading import Lock, Thread, BoundedSemaphore
|
||||
from Queue import Queue, Empty
|
||||
import traceback
|
||||
import thread
|
||||
from thread import get_ident # python < 2.6 support
|
||||
import sys
|
||||
from offlineimap.ui import getglobalui
|
||||
|
||||
@ -149,7 +149,6 @@ class ExitNotifyThread(Thread):
|
||||
exited and to provide for the ability for it to find out why."""
|
||||
def run(self):
|
||||
global exitthreads, profiledir
|
||||
self.threadid = thread.get_ident()
|
||||
try:
|
||||
if not profiledir: # normal case
|
||||
Thread.run(self)
|
||||
@ -164,7 +163,7 @@ class ExitNotifyThread(Thread):
|
||||
except SystemExit:
|
||||
pass
|
||||
prof.dump_stats( \
|
||||
profiledir + "/" + str(self.threadid) + "_" + \
|
||||
profiledir + "/" + str(get_ident()) + "_" + \
|
||||
self.getName() + ".prof")
|
||||
except:
|
||||
self.setExitCause('EXCEPTION')
|
||||
|
@ -18,7 +18,7 @@
|
||||
|
||||
from threading import RLock, currentThread
|
||||
from offlineimap.ui.UIBase import UIBase
|
||||
import thread
|
||||
from thread import get_ident # python < 2.6 support
|
||||
|
||||
class BlinkenBase:
|
||||
"""This is a mix-in class that should be mixed in with either UIBase
|
||||
@ -103,7 +103,7 @@ class BlinkenBase:
|
||||
UIBase.threadExited(s, thread)
|
||||
|
||||
def gettf(s):
|
||||
threadid = thread.get_ident()
|
||||
threadid = get_ident()
|
||||
accountname = s.getthreadaccount()
|
||||
|
||||
s.tflock.acquire()
|
||||
|
Loading…
Reference in New Issue
Block a user