欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页

Python 定时器

程序员文章站 2022-05-17 21:25:24
...
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()