[PATCH 1/5] IMAP IDLE cleanup(1): Move idle callback out of loop

Sebastian Spaeth Sebastian at SSpaeth.de
Mon Sep 12 08:37:53 UTC 2011


Don't redefine the idle callback function on every run in the while
loop, define it once when we enter the function.

Signed-off-by: Sebastian Spaeth <Sebastian at SSpaeth.de>
---
 offlineimap/imapserver.py |   21 +++++++++++----------
 1 files changed, 11 insertions(+), 10 deletions(-)

diff --git a/offlineimap/imapserver.py b/offlineimap/imapserver.py
index 05d8111..a07cdc8 100644
--- a/offlineimap/imapserver.py
+++ b/offlineimap/imapserver.py
@@ -493,21 +493,22 @@ class IdleThread(object):
         ui.unregisterthread(currentThread())
 
     def idle(self):
+        def callback(args):
+            result, cb_arg, exc_data = args
+            if exc_data is None:
+                if not self.event.isSet():
+                    self.needsync = True
+                    self.event.set()
+            else:
+                # We got an "abort" signal.
+                self.imapaborted = True
+                self.stop()
+
         while True:
             if self.event.isSet():
                 return
             self.needsync = False
             self.imapaborted = False
-            def callback(args):
-                result, cb_arg, exc_data = args
-                if exc_data is None:
-                    if not self.event.isSet():
-                        self.needsync = True
-                        self.event.set()
-                else:
-                    # We got an "abort" signal.
-                    self.imapaborted = True
-                    self.stop()
 
             success = False # successfully selected FOLDER?
             while not success:
-- 
1.7.4.1




More information about the OfflineIMAP-project mailing list