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:
parent
ba3a698a67
commit
03566b2037
@ -18,7 +18,6 @@
|
|||||||
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, Thread, Event, currentThread
|
from threading import Lock, BoundedSemaphore, Thread, Event, currentThread
|
||||||
from thread import get_ident # python < 2.6 support
|
|
||||||
import offlineimap.accounts
|
import offlineimap.accounts
|
||||||
import hmac
|
import hmac
|
||||||
import socket
|
import socket
|
||||||
@ -167,6 +166,7 @@ class IMAPServer:
|
|||||||
|
|
||||||
self.semaphore.acquire()
|
self.semaphore.acquire()
|
||||||
self.connectionlock.acquire()
|
self.connectionlock.acquire()
|
||||||
|
curThread = currentThread()
|
||||||
imapobj = None
|
imapobj = None
|
||||||
|
|
||||||
if len(self.availableconnections): # One is available.
|
if len(self.availableconnections): # One is available.
|
||||||
@ -176,7 +176,7 @@ class IMAPServer:
|
|||||||
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] == get_ident():
|
if self.lastowner[tryobj] == curThread.ident:
|
||||||
imapobj = tryobj
|
imapobj = tryobj
|
||||||
del(self.availableconnections[i])
|
del(self.availableconnections[i])
|
||||||
break
|
break
|
||||||
@ -184,7 +184,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] = get_ident()
|
self.lastowner[imapobj] = curThread.ident
|
||||||
self.connectionlock.release()
|
self.connectionlock.release()
|
||||||
return imapobj
|
return imapobj
|
||||||
|
|
||||||
@ -297,7 +297,7 @@ class IMAPServer:
|
|||||||
|
|
||||||
self.connectionlock.acquire()
|
self.connectionlock.acquire()
|
||||||
self.assignedconnections.append(imapobj)
|
self.assignedconnections.append(imapobj)
|
||||||
self.lastowner[imapobj] = get_ident()
|
self.lastowner[imapobj] = curThread.ident
|
||||||
self.connectionlock.release()
|
self.connectionlock.release()
|
||||||
return imapobj
|
return imapobj
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
|
@ -15,13 +15,12 @@
|
|||||||
# along with this program; if not, write to the Free Software
|
# along with this program; if not, write to the Free Software
|
||||||
# Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
|
# 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:
|
try:
|
||||||
from Queue import Queue, Empty
|
from Queue import Queue, Empty
|
||||||
except ImportError: # python3
|
except ImportError: # python3
|
||||||
from queue import Queue, Empty
|
from queue import Queue, Empty
|
||||||
import traceback
|
import traceback
|
||||||
from thread import get_ident # python < 2.6 support
|
|
||||||
import os.path
|
import os.path
|
||||||
import sys
|
import sys
|
||||||
from offlineimap.ui import getglobalui
|
from offlineimap.ui import getglobalui
|
||||||
@ -152,7 +151,6 @@ class ExitNotifyThread(Thread):
|
|||||||
|
|
||||||
def run(self):
|
def run(self):
|
||||||
global exitthreads
|
global exitthreads
|
||||||
self.threadid = get_ident()
|
|
||||||
try:
|
try:
|
||||||
if not ExitNotifyThread.profiledir: # normal case
|
if not ExitNotifyThread.profiledir: # normal case
|
||||||
Thread.run(self)
|
Thread.run(self)
|
||||||
@ -167,7 +165,7 @@ class ExitNotifyThread(Thread):
|
|||||||
except SystemExit:
|
except SystemExit:
|
||||||
pass
|
pass
|
||||||
prof.dump_stats(os.path.join(ExitNotifyThread.profiledir,
|
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:
|
except Exception as e:
|
||||||
# Thread exited with Exception, store it
|
# Thread exited with Exception, store it
|
||||||
tb = traceback.format_exc()
|
tb = traceback.format_exc()
|
||||||
|
@ -16,7 +16,6 @@
|
|||||||
# Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
|
# Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
|
||||||
|
|
||||||
from threading import RLock, currentThread, Lock, Event
|
from threading import RLock, currentThread, Lock, Event
|
||||||
from thread import get_ident # python < 2.6 support
|
|
||||||
from collections import deque
|
from collections import deque
|
||||||
import time
|
import time
|
||||||
import sys
|
import sys
|
||||||
|
Loading…
Reference in New Issue
Block a user