]> code.delx.au - offlineimap/commitdiff
Rework keepalive to use time.sleep() instead of event.wait()
authorJohn Goerzen <jgoerzen@complete.org>
Sat, 2 Aug 2008 22:04:32 +0000 (17:04 -0500)
committerJohn Goerzen <jgoerzen@complete.org>
Sat, 2 Aug 2008 22:44:03 +0000 (17:44 -0500)
This should improve power-management abilities some more

The catch is that we can't wait any longer for the kathread to
terminate.  We were waiting for this in some cases.  This is probably
not a big deal.

fixes deb#434074
fixes #66

offlineimap/accounts.py
offlineimap/imapserver.py
offlineimap/repository/Base.py
offlineimap/repository/IMAP.py

index 8e96347944f58c37fcada83fd98fb18dca16e23a..a86485d88d5cf2bd4f8bd27e47c73ad9ad75df77 100644 (file)
@@ -83,16 +83,10 @@ class Account(CustomConfig.ConfigHelperMixin):
         
         refreshperiod = int(self.refreshperiod * 60)
         sleepresult = self.ui.sleep(refreshperiod)
-        if sleepresult == 2:
-            # Cancel keep-alive, but don't bother terminating threads
-            for item in kaobjs:
-                item.stopkeepalive(abrupt = 1)
-            return sleepresult
-        else:
-            # Cancel keep-alive and wait for thread to terminate.
-            for item in kaobjs:
-                item.stopkeepalive(abrupt = 0)
-            return sleepresult
+        # Cancel keepalive
+        for item in kaobjs:
+            item.stopkeepalive()
+        return sleepresult
             
 class AccountSynchronizationMixin:
     def syncrunner(self):
index 7d99e19de2c7e9d6b13aa36f88db25ea425ab62a..4c89cca66cf125bcd97da39875656f0222fe88b2 100644 (file)
@@ -20,7 +20,7 @@ import imaplib
 from offlineimap import imaplibutil, imaputil, threadutil
 from offlineimap.ui import UIBase
 from threading import *
-import thread, hmac, os
+import thread, hmac, os, time
 import base64
 
 try:
@@ -309,7 +309,7 @@ class IMAPServer:
         ui.debug('imap', 'keepalive thread started')
         while 1:
             ui.debug('imap', 'keepalive: top of loop')
-            event.wait(timeout)
+            time.sleep(timeout)
             ui.debug('imap', 'keepalive: after wait')
             if event.isSet():
                 ui.debug('imap', 'keepalive: event is set; exiting')
index ed07b572b87872e3749a9e3ee0eddae90d7cfde1..ea1fd50ef674cf288acecd654ac93d68fb9ead52 100644 (file)
@@ -171,8 +171,8 @@ class BaseRepository(CustomConfig.ConfigHelperMixin):
         """The default implementation will do nothing."""
         pass
 
-    def stopkeepalive(self, abrupt = 0):
-        """Stop keep alive.  If abrupt is 1, stop it but don't bother waiting
+    def stopkeepalive(self):
+        """Stop keep alive, but don't bother waiting
         for the threads to terminate."""
         pass
     
index e5be9eefaf4d24c4bdad3d3be5da96a3e95bd534..8c5f46942b54c406fb04d97e3b570ea4d6d5023e 100644 (file)
@@ -57,14 +57,12 @@ class IMAPRepository(BaseRepository):
         self.kathread.setDaemon(1)
         self.kathread.start()
 
-    def stopkeepalive(self, abrupt = 0):
+    def stopkeepalive(self):
         if not hasattr(self, 'kaevent'):
             # Keepalive is not active.
             return
 
         self.kaevent.set()
-        if not abrupt:
-            self.kathread.join()
         del self.kathread
         del self.kaevent