Python3 多线程 学习 threading

#-*- coding:utf-8 --*-
#多线程测试 

import time
import datetime
import threading

def worker():

    print("未用多线程")
    time.sleep(1)

    return

def worker2():
    print("使用多线程")
    time.sleep(1)
    return

if __name__ == "__main__"    :
    d1 = datetime.datetime.now()    
    for i in range(5):
        worker()
    d2 = datetime.datetime.now()
    print(d2-d1)

    d1 = datetime.datetime.now()    
    for j in range(5):
        t = threading.Thread(target = worker2)
        t.start()
    d2 = datetime.datetime.now()
    print(d2 - d1)
    print("current has %d threads" % (threading.activeCount() - 1))
原文地址:https://www.cnblogs.com/lrzy/p/5570719.html