~divmod-dev/divmod.org/trunk

« back to all changes in this revision

Viewing changes to Epsilon/epsilon/hotfixes/internet_task_clock.py

  • Committer: Jean-Paul Calderone
  • Date: 2014-06-29 20:33:04 UTC
  • mfrom: (2749.1.1 remove-epsilon-1325289)
  • Revision ID: exarkun@twistedmatrix.com-20140629203304-gdkmbwl1suei4m97
mergeĀ lp:~exarkun/divmod.org/remove-epsilon-1325289

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
"""
2
 
Fix from Twisted r20480.
3
 
"""
4
 
from twisted.internet.task import Clock
5
 
from twisted.internet import base
6
 
 
7
 
def callLater(self, when, what, *a, **kw):
8
 
    """
9
 
    Copied from twisted.internet.task.Clock, r20480.  Fixes the bug
10
 
    where the wrong DelayedCall would sometimes be returned.
11
 
    """
12
 
    dc =  base.DelayedCall(self.seconds() + when,
13
 
                           what, a, kw,
14
 
                           self.calls.remove,
15
 
                           lambda c: None,
16
 
                           self.seconds)
17
 
    self.calls.append(dc)
18
 
    self.calls.sort(lambda a, b: cmp(a.getTime(), b.getTime()))
19
 
    return dc
20
 
 
21
 
def clockIsBroken():
22
 
    """
23
 
    Returns whether twisted.internet.task.Clock has the bug that
24
 
    returns the wrong DelayedCall or not.
25
 
    """
26
 
    clock = Clock()
27
 
    dc1 = clock.callLater(10, lambda: None)
28
 
    dc2 = clock.callLater(1, lambda: None)
29
 
    if dc1 is dc2:
30
 
        return True
31
 
    else:
32
 
        return False
33
 
 
34
 
def install():
35
 
    """
36
 
    Insert the fixed callLater method.
37
 
    """
38
 
    Clock.callLater = callLater