Пример #1
0
def exc_after(seconds, *throw_args):
    warnings.warn("Instead of exc_after, which is deprecated, use "
                  "Timeout(seconds, exception)",
                  DeprecationWarning, stacklevel=2)
    if seconds is None:  # dummy argument, do nothing
        return timer.Timer(seconds, lambda: None)
    hub = hubs.get_hub()
    return hub.schedule_call_local(seconds, getcurrent().throw, *throw_args)
Пример #2
0
def benchmark_hub_timers(timeouts):
    scheduled = []

    for timeout in timeouts:
        t = timer.Timer(timeout, work, timeout)
        t.schedule()
        scheduled.append(t)

    hub.prepare_timers()
    hub.fire_timers(hub.clock() + 11)
    hub.prepare_timers()
Пример #3
0
 def schedule_call_global(self, seconds, cb, *args, **kw):
     """Schedule a callable to be called after 'seconds' seconds have
     elapsed. The timer will NOT be canceled if the current greenlet has
     exited before the timer fires.
         seconds: The number of seconds to wait.
         cb: The callable to call after the given time.
         *args: Arguments to pass to the callable when called.
         **kw: Keyword arguments to pass to the callable when called.
     """
     t = timer.Timer(seconds, cb, *args, **kw)
     self.add_timer(t)
     return t
Пример #4
0
 def test_copy(self):
     t = timer.Timer(0, lambda: None)
     t2 = t.copy()
     assert t.seconds == t2.seconds
     assert t.tpl == t2.tpl
     assert t.called == t2.called
Пример #5
0
if len(sys.argv) >= 2:
    timer_count = int(sys.argv[1])

l = []

def work(n):
    l.append(n)

timeouts = [random.uniform(0, 10) for x in six.moves.range(timer_count)]

hub = get_hub()

start = time.time()

scheduled = []

for timeout in timeouts:
    t = timer.Timer(timeout, work, timeout)
    t.schedule()

    scheduled.append(t)

hub.prepare_timers()
hub.fire_timers(time.time()+11)
hub.prepare_timers()

end = time.time()

print("Duration: %f" % (end-start,))