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

  


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM