线程数量

import time
import threading
from threading import Thread
def sing():
    for i in range(5):
        print('唱第%d首歌'%i)
        time.sleep(0.5)
def dance():
    for i in range(5):
        print('跳第%d段舞'%i)
        time.sleep(0.5)
if __name__ == '__main__':
    t1=Thread(target=sing)
    t2=Thread(target=dance)
    t1.start()
    #t1.join()
    t2.start()
    #t2.join()

    while True:
        count=len(threading.enumerate())
        print('当前线程数',count)
        if count<=1:
            break

你可能感兴趣的:(线程数量)