/head: changeset 93
Optimized acquireconnection to try to return the last connection owned by this thread
This commit is contained in:
parent
120076256f
commit
8029c6a25e
@ -8,8 +8,9 @@ offlineimap (2.0.8) unstable; urgency=low
|
||||
bug.
|
||||
* Modified Maildir folder to unlink messages with T flag in
|
||||
cachemessagelist()
|
||||
* My own box now syncs in 3 seconds.
|
||||
|
||||
-- John Goerzen <jgoerzen@complete.org> Wed, 10 Jul 2002 12:29:30 -0500
|
||||
-- John Goerzen <jgoerzen@complete.org> Tue, 9 Jul 2002 23:29:30 -0500
|
||||
|
||||
offlineimap (2.0.7) unstable; urgency=low
|
||||
|
||||
|
@ -18,6 +18,7 @@
|
||||
|
||||
from offlineimap import imaplib, imaputil, threadutil
|
||||
from threading import *
|
||||
import thread
|
||||
|
||||
class UsefulIMAPMixIn:
|
||||
def getstate(self):
|
||||
@ -64,6 +65,7 @@ class IMAPServer:
|
||||
self.maxconnections = maxconnections
|
||||
self.availableconnections = []
|
||||
self.assignedconnections = []
|
||||
self.lastowner = {}
|
||||
self.semaphore = BoundedSemaphore(self.maxconnections)
|
||||
self.connectionlock = Lock()
|
||||
self.reference = reference
|
||||
@ -97,9 +99,22 @@ class IMAPServer:
|
||||
imapobj = None
|
||||
|
||||
if len(self.availableconnections): # One is available.
|
||||
# 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:
|
||||
imapobj = tryobj
|
||||
del(self.availableconnections[i])
|
||||
break
|
||||
if not imapobj:
|
||||
imapobj = self.availableconnections[0]
|
||||
self.assignedconnections.append(imapobj)
|
||||
del(self.availableconnections[0])
|
||||
self.assignedconnections.append(imapobj)
|
||||
self.lastowner[imapobj] = thread.get_ident()
|
||||
self.connectionlock.release()
|
||||
return imapobj
|
||||
|
||||
@ -124,6 +139,7 @@ class IMAPServer:
|
||||
|
||||
self.connectionlock.acquire()
|
||||
self.assignedconnections.append(imapobj)
|
||||
self.lastowner[imapobj] = thread.get_ident()
|
||||
self.connectionlock.release()
|
||||
return imapobj
|
||||
|
||||
@ -146,6 +162,7 @@ class IMAPServer:
|
||||
imapobj.logout()
|
||||
self.assignedconnections = []
|
||||
self.availableconnections = []
|
||||
self.lastowner = {}
|
||||
self.connectionlock.release()
|
||||
|
||||
def keepalive(self, timeout, event):
|
||||
@ -168,14 +185,14 @@ class IMAPServer:
|
||||
for i in range(numconnections):
|
||||
imapobj = self.acquireconnection()
|
||||
imapobjs.append(imapobj)
|
||||
thread = threadutil.ExitNotifyThread(target = imapobj.noop)
|
||||
thread.setDaemon(1)
|
||||
thread.start()
|
||||
threads.append(thread)
|
||||
thr = threadutil.ExitNotifyThread(target = imapobj.noop)
|
||||
thr.setDaemon(1)
|
||||
thr.start()
|
||||
threads.append(thr)
|
||||
|
||||
for thread in threads:
|
||||
for thr in threads:
|
||||
# Make sure all the commands have completed.
|
||||
thread.join()
|
||||
thr.join()
|
||||
|
||||
for imapobj in imapobjs:
|
||||
self.releaseconnection(imapobj)
|
||||
|
Loading…
Reference in New Issue
Block a user