[PATCH 3/6] Change keepalive() to spawn IdleThreads
Ethan Glasser-Camp
ethan at betacantrips.com
Wed May 18 13:48:54 BST 2011
This is the commit that enables IDLE support. In order to do this, we
hijack the keepalive method. Instead of just sending NOOPs, it now
sends IDLE and responds accordingly, thanks to the IdleThread class.
This code was originally by James Bunton <jamesbunton at fastmail.fm>.
Signed-off-by: Ethan Glasser-Camp <ethan at betacantrips.com>
---
offlineimap/imapserver.py | 30 +++++++++++++-----------------
1 files changed, 13 insertions(+), 17 deletions(-)
diff --git a/offlineimap/imapserver.py b/offlineimap/imapserver.py
index ebd867e..ceea3dc 100644
--- a/offlineimap/imapserver.py
+++ b/offlineimap/imapserver.py
@@ -330,8 +330,6 @@ class IMAPServer:
self.ui.debug('imap', 'keepalive thread started')
while 1:
self.ui.debug('imap', 'keepalive: top of loop')
- time.sleep(timeout)
- self.ui.debug('imap', 'keepalive: after wait')
if event.isSet():
self.ui.debug('imap', 'keepalive: event is set; exiting')
return
@@ -342,29 +340,27 @@ class IMAPServer:
self.connectionlock.release()
self.ui.debug('imap', 'keepalive: connectionlock released')
threads = []
- imapobjs = []
for i in range(numconnections):
self.ui.debug('imap', 'keepalive: processing connection %d of %d' % (i, numconnections))
- imapobj = self.acquireconnection()
- self.ui.debug('imap', 'keepalive: connection %d acquired' % i)
- imapobjs.append(imapobj)
- thr = threadutil.ExitNotifyThread(target = imapobj.noop)
- thr.setDaemon(1)
- thr.start()
- threads.append(thr)
+ if len(self.idlefolders) > i:
+ idler = IdleThread(self, self.idlefolders[i])
+ else:
+ idler = IdleThread(self)
+ idler.start()
+ threads.append(idler)
self.ui.debug('imap', 'keepalive: thread started')
+ self.ui.debug('imap', 'keepalive: waiting for timeout')
+ event.wait(timeout)
+ self.ui.debug('imap', 'keepalive: after wait')
+
self.ui.debug('imap', 'keepalive: joining threads')
- for thr in threads:
+ for idler in threads:
# Make sure all the commands have completed.
- thr.join()
-
- self.ui.debug('imap', 'keepalive: releasing connections')
-
- for imapobj in imapobjs:
- self.releaseconnection(imapobj)
+ idler.stop()
+ idler.join()
self.ui.debug('imap', 'keepalive: bottom of loop')
--
1.7.4.1
More information about the OfflineIMAP-project
mailing list