python 使用多线程同时执行多个函数

import threading
import time

def test1():
    print(1+5)

def test2():
    print(5+8)

def test3():
    print(5 + 8)
def test4():
    print(5 + 8)
def test5():
    print(5 + 8)

if __name__=='__main__':
    threads=[threading.Thread(target=test1),
             threading.Thread(target=test2),
             threading.Thread(target=test3),
             threading.Thread(target=test4),
             threading.Thread(target=test5)]
    for i in threads:
        i.start()
        print(time.time())

运行结果:
6
1612968412.95072
13
1612968412.95072
13
1612968412.95072
13
1612968412.95072
13
1612968412.95072

  

posted @ 2021-02-10 22:51  萱娃  阅读(1275)  评论(0编辑  收藏  举报