]> git.ipfire.org Git - thirdparty/tornado.git/commitdiff
Fix for python2.5: heapq used to use __le__ instead of __lt__
authorBen Darnell <ben@bendarnell.com>
Sun, 1 May 2011 21:33:28 +0000 (14:33 -0700)
committerBen Darnell <ben@bendarnell.com>
Sun, 1 May 2011 21:33:28 +0000 (14:33 -0700)
tornado/ioloop.py

index b7101672fb681c7205d87b0c679bc476255aea68..a7bdffc3c8c6484681c2ea09121376c299f867f8 100644 (file)
@@ -397,10 +397,18 @@ class _Timeout(object):
         self.deadline = deadline
         self.callback = callback
 
+    # Comparison methods to sort by deadline, with object id as a tiebreaker
+    # to guarantee a consistent ordering.  The heapq module uses __le__
+    # in python2.5, and __lt__ in 2.6+ (sort() and most other comparisons
+    # use __lt__).  
     def __lt__(self, other):
         return ((self.deadline, id(self)) <
                 (other.deadline, id(other)))
 
+    def __le__(self, other):
+        return ((self.deadline, id(self)) <=
+                (other.deadline, id(other)))
+
 
 class PeriodicCallback(object):
     """Schedules the given callback to be called periodically.