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 import imaplibutil, imaputil, threadutil, OfflineImapError
|
||||||
from offlineimap.ui import getglobalui
|
from offlineimap.ui import getglobalui
|
||||||
from threading import Lock, BoundedSemaphore
|
from threading import Lock, BoundedSemaphore
|
||||||
import thread
|
from thread import get_ident # python < 2.6 support
|
||||||
import time
|
import time
|
||||||
import hmac
|
import hmac
|
||||||
import socket
|
import socket
|
||||||
@ -167,11 +167,10 @@ class IMAPServer:
|
|||||||
# Try to find one that previously belonged to this thread
|
# Try to find one that previously belonged to this thread
|
||||||
# as an optimization. Start from the back since that's where
|
# as an optimization. Start from the back since that's where
|
||||||
# they're popped on.
|
# they're popped on.
|
||||||
threadid = thread.get_ident()
|
|
||||||
imapobj = None
|
imapobj = None
|
||||||
for i in range(len(self.availableconnections) - 1, -1, -1):
|
for i in range(len(self.availableconnections) - 1, -1, -1):
|
||||||
tryobj = self.availableconnections[i]
|
tryobj = self.availableconnections[i]
|
||||||
if self.lastowner[tryobj] == threadid:
|
if self.lastowner[tryobj] == get_ident():
|
||||||
imapobj = tryobj
|
imapobj = tryobj
|
||||||
del(self.availableconnections[i])
|
del(self.availableconnections[i])
|
||||||
break
|
break
|
||||||
@ -179,7 +178,7 @@ class IMAPServer:
|
|||||||
imapobj = self.availableconnections[0]
|
imapobj = self.availableconnections[0]
|
||||||
del(self.availableconnections[0])
|
del(self.availableconnections[0])
|
||||||
self.assignedconnections.append(imapobj)
|
self.assignedconnections.append(imapobj)
|
||||||
self.lastowner[imapobj] = thread.get_ident()
|
self.lastowner[imapobj] = get_ident()
|
||||||
self.connectionlock.release()
|
self.connectionlock.release()
|
||||||
return imapobj
|
return imapobj
|
||||||
|
|
||||||
@ -266,7 +265,7 @@ class IMAPServer:
|
|||||||
|
|
||||||
self.connectionlock.acquire()
|
self.connectionlock.acquire()
|
||||||
self.assignedconnections.append(imapobj)
|
self.assignedconnections.append(imapobj)
|
||||||
self.lastowner[imapobj] = thread.get_ident()
|
self.lastowner[imapobj] = get_ident()
|
||||||
self.connectionlock.release()
|
self.connectionlock.release()
|
||||||
return imapobj
|
return imapobj
|
||||||
except Exception, e:
|
except Exception, e:
|
||||||
|
@ -19,7 +19,7 @@
|
|||||||
from threading import Lock, Thread, BoundedSemaphore
|
from threading import Lock, Thread, BoundedSemaphore
|
||||||
from Queue import Queue, Empty
|
from Queue import Queue, Empty
|
||||||
import traceback
|
import traceback
|
||||||
import thread
|
from thread import get_ident # python < 2.6 support
|
||||||
import sys
|
import sys
|
||||||
from offlineimap.ui import getglobalui
|
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."""
|
exited and to provide for the ability for it to find out why."""
|
||||||
def run(self):
|
def run(self):
|
||||||
global exitthreads, profiledir
|
global exitthreads, profiledir
|
||||||
self.threadid = thread.get_ident()
|
|
||||||
try:
|
try:
|
||||||
if not profiledir: # normal case
|
if not profiledir: # normal case
|
||||||
Thread.run(self)
|
Thread.run(self)
|
||||||
@ -164,7 +163,7 @@ class ExitNotifyThread(Thread):
|
|||||||
except SystemExit:
|
except SystemExit:
|
||||||
pass
|
pass
|
||||||
prof.dump_stats( \
|
prof.dump_stats( \
|
||||||
profiledir + "/" + str(self.threadid) + "_" + \
|
profiledir + "/" + str(get_ident()) + "_" + \
|
||||||
self.getName() + ".prof")
|
self.getName() + ".prof")
|
||||||
except:
|
except:
|
||||||
self.setExitCause('EXCEPTION')
|
self.setExitCause('EXCEPTION')
|
||||||
|
@ -18,7 +18,7 @@
|
|||||||
|
|
||||||
from threading import RLock, currentThread
|
from threading import RLock, currentThread
|
||||||
from offlineimap.ui.UIBase import UIBase
|
from offlineimap.ui.UIBase import UIBase
|
||||||
import thread
|
from thread import get_ident # python < 2.6 support
|
||||||
|
|
||||||
class BlinkenBase:
|
class BlinkenBase:
|
||||||
"""This is a mix-in class that should be mixed in with either UIBase
|
"""This is a mix-in class that should be mixed in with either UIBase
|
||||||
@ -103,7 +103,7 @@ class BlinkenBase:
|
|||||||
UIBase.threadExited(s, thread)
|
UIBase.threadExited(s, thread)
|
||||||
|
|
||||||
def gettf(s):
|
def gettf(s):
|
||||||
threadid = thread.get_ident()
|
threadid = get_ident()
|
||||||
accountname = s.getthreadaccount()
|
accountname = s.getthreadaccount()
|
||||||
|
|
||||||
s.tflock.acquire()
|
s.tflock.acquire()
|
||||||
|
Loading…
Reference in New Issue
Block a user