示例#1
0
def test_start_all():
    t = timer.Timer()
    a = Action()
    t.add(a.a1, 15).start()
    t.add(a.a2, 10).start()
    assert len(t) == 2
    time.sleep(.02)
    t.service()
    assert a.t1 is True
    assert a.t2 is True
示例#2
0
def test_no_start():
    t = timer.Timer()
    a = Action()
    t.add(a.a1, 15)
    t.add(a.a2, 10)
    assert len(t) == 0
    time.sleep(.02)
    t.service()
    assert a.t1 is False
    assert a.t2 is False
示例#3
0
def test_start_restart():
    t = timer.Timer()
    a = Action()
    t.add(a.a1, 10).start()
    t2 = t.add(a.a2, 20).start()
    time.sleep(.015)
    t.service()
    assert a.t1 is True
    assert a.t2 is False
    t2.re_start()
    time.sleep(.015)
    t.service()
    assert a.t1 is True
    assert a.t2 is False
示例#4
0
def test_start_cancel():
    t = timer.Timer()
    a = Action()
    t.add(a.a1, 10).start()
    t2 = t.add(a.a2, 20).start()
    time.sleep(.015)
    t.service()
    assert a.t1 is True
    assert a.t2 is False
    t2.cancel()
    assert len(t) == 1
    time.sleep(.01)
    t.service()
    assert len(t) == 0
    assert a.t1 is True
    assert a.t2 is False
示例#5
0
def test_backoff():
    t = timer.Timer()
    a = ActionBackoff()
    t1 = t.add_backoff(a.a1, 10, 30, 2).start()
    time.sleep(.015)
    t.service()
    assert a.c1 == 1
    t1.start()
    time.sleep(.01)
    t.service()
    assert a.c1 == 1
    time.sleep(.02)
    t.service()
    assert a.c1 == 2
    t1.start()
    time.sleep(.021)
    t.service()
    assert a.c1 == 2
    time.sleep(.01)
    t.service()
    assert a.c1 == 3
示例#6
0
import time

import spindrift.timer as timer


class Action(object):
    def __init__(self):
        self.is_running = True

    def action(self):
        self.is_running = False


t = timer.Timer()
a = Action()
t1 = t.add_hourly(a.action).start()
while a.is_running:
    print('tick', t1)
    time.sleep(10)
    t.service()