Simplify the keepalive code a bit

Should not change behavior.
Signed-off-by: Sebastian Spaeth <Sebastian@SSpaeth.de>
This commit is contained in:
Sebastian Spaeth 2011-10-27 16:56:18 +02:00
parent cbec8bb5b2
commit f6f8fc8528
2 changed files with 10 additions and 17 deletions

View File

@ -389,47 +389,40 @@ class IMAPServer:
to be invoked in a separate thread, which should be join()'d after to be invoked in a separate thread, which should be join()'d after
the event is set.""" the event is set."""
self.ui.debug('imap', 'keepalive thread started') self.ui.debug('imap', 'keepalive thread started')
while 1: while not event.isSet():
self.ui.debug('imap', 'keepalive: top of loop')
if event.isSet():
self.ui.debug('imap', 'keepalive: event is set; exiting')
return
self.ui.debug('imap', 'keepalive: acquiring connectionlock')
self.connectionlock.acquire() self.connectionlock.acquire()
numconnections = len(self.assignedconnections) + \ numconnections = len(self.assignedconnections) + \
len(self.availableconnections) len(self.availableconnections)
self.connectionlock.release() self.connectionlock.release()
self.ui.debug('imap', 'keepalive: connectionlock released')
threads = [] threads = []
for i in range(numconnections): for i in range(numconnections):
self.ui.debug('imap', 'keepalive: processing connection %d of %d' % (i, numconnections)) self.ui.debug('imap', 'keepalive: processing connection %d of %d' % (i, numconnections))
if len(self.idlefolders) > i: if len(self.idlefolders) > i:
# IDLE thread
idler = IdleThread(self, self.idlefolders[i]) idler = IdleThread(self, self.idlefolders[i])
else: else:
# NOOP thread
idler = IdleThread(self) idler = IdleThread(self)
idler.start() idler.start()
threads.append(idler) threads.append(idler)
self.ui.debug('imap', 'keepalive: thread started')
self.ui.debug('imap', 'keepalive: waiting for timeout') self.ui.debug('imap', 'keepalive: waiting for timeout')
event.wait(timeout) event.wait(timeout)
self.ui.debug('imap', 'keepalive: after wait') self.ui.debug('imap', 'keepalive: after wait')
self.ui.debug('imap', 'keepalive: joining threads')
for idler in threads: for idler in threads:
# Make sure all the commands have completed. # Make sure all the commands have completed.
idler.stop() idler.stop()
idler.join() idler.join()
self.ui.debug('imap', 'keepalive: all threads joined')
self.ui.debug('imap', 'keepalive: bottom of loop') self.ui.debug('imap', 'keepalive: event is set; exiting')
return
def verifycert(self, cert, hostname): def verifycert(self, cert, hostname):
'''Verify that cert (in socket.getpeercert() format) matches hostname. '''Verify that cert (in socket.getpeercert() format) matches hostname.
CRLs are not handled. CRLs are not handled.
Returns error message if any problems are found and None on success. Returns error message if any problems are found and None on success.
''' '''
errstr = "CA Cert verifying failed: " errstr = "CA Cert verifying failed: "
@ -508,7 +501,7 @@ class IdleThread(object):
finally: finally:
if imapobj: if imapobj:
self.parent.releaseconnection(imapobj) self.parent.releaseconnection(imapobj)
self.stop_sig.wait() # wait until we are supposed to quit self.stop_sig.wait() # wait until we are supposed to quit
def dosync(self): def dosync(self):
remoterepos = self.parent.repos remoterepos = self.parent.repos

View File

@ -229,4 +229,4 @@ class BaseRepository(object, CustomConfig.ConfigHelperMixin):
"""Stop keep alive, but don't bother waiting """Stop keep alive, but don't bother waiting
for the threads to terminate.""" for the threads to terminate."""
pass pass