]> code.delx.au - bg-scripts/blobdiff - asyncsched.py
Always use poll
[bg-scripts] / asyncsched.py
index 22eb78808e1e307ba3ef2dd01ee8e671d43fa020..7edba812adcad893b12ec5bf987877ed5754e19f 100644 (file)
@@ -15,8 +15,11 @@ class Task(object):
         self.time = time.time() + delay
         self.func = lambda: func(*args, **kwargs)
     
-    def __cmp__(self, other):
-        return cmp(self.time, other.time)
+    def __lt__(self, other):
+        return self.time < other.time
+
+    def __eq__(self, other):
+        return self.time == other.time
 
     def __call__(self):
         f = self.func
@@ -38,14 +41,6 @@ def loop(timeout=30.0, use_poll=False):
     running = True
     oldhandler = signal.signal(signal.SIGTERM, exit)
 
-    if use_poll:
-        if hasattr(select, 'poll'):
-            poll_fun = asyncore.poll3
-        else:
-            poll_fun = asyncore.poll2
-    else:
-        poll_fun = asyncore.poll
-
     while running:
         now = time.time()
         while tasks and tasks[0].time < now:
@@ -56,7 +51,7 @@ def loop(timeout=30.0, use_poll=False):
         if tasks:
             t = max(min(t, tasks[0].time - now), 0)
 
-        poll_fun(timeout=t)
+        asyncore.poll2(timeout=t)
     
     signal.signal(signal.SIGTERM, oldhandler)