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)
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()
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
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
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,))