class _PollsHandler(object): """ Handler for the signals from the Polls Model """ def __init__(self, func, *args): self.looping_call = LoopingCall(func, *args) def post_save_cb(self, sender, **kwargs): poll = kwargs["instance"] self.looping_call.start(poll.period) def post_delete_cb(self, sender, **kwargs): self.looping_call.stop()
def test_looping_call(self): self.total = 0 def foo(arg): self.total += arg p = LoopingCall(foo, 1) p.start(0.1) time.sleep(1) p.stop() self.assertEquals(9, self.total) time.sleep(1) self.assertEquals(9, self.total) p.start(0.4) time.sleep(1) p.stop() self.assertEquals(11, self.total)
def __init__(self, func, *args): self.looping_call = LoopingCall(func, *args)