python同时执行两个函数

使用两个线程同时执行两个函数,

def fun1():
    while True:
        time.sleep(2)
        print("fun1")

def fun2():
    while True:
        time.sleep(6)
        print("fun2")

threads = []
threads.append(threading.Thread(target=fun1))
threads.append(threading.Thread(target=fun2))
print(threads)
if __name__ == '__main__':
    for t in threads:
        print(t)
        t.start()
View Code

 

posted on 2019-06-30 18:35  吃我一枪  阅读(11565)  评论(0编辑  收藏  举报

导航