Python 定時器

bule_sky_fuxing發表於2017-06-14
import threading
class Person(object):
    def __init__(self):
        print "init person"

    def speak(self):
        print "speak"

if __name__ == "__main__":
    p = Person()
    count = 5
    while count:
        timer = threading.Timer(5, Person.speak, (p,))
        print "begin"
        count -= 1
        timer.start()
        timer.join()
        print "end join"


import time
import threading

def hello():
    print 'hello'

for i in range(3):
    t = threading.Timer(5.0, hello)
    t.start()
    t.join()


相關文章