Python 限制執行緒的最大數量(Sem

import threading  import time    sem=threading.Semaphore(4)  #限制執行緒的最大數量為4個    def gothread():      with  sem:  #鎖定執行緒的最大數量          for i in range(8):              print(threading.current_thread().name,i)              time.sleep(1)    for i in range(5):      threading.Thread(target=gothread).start()