同时可以执行的线程数,信号量常用于类似php,ssh等的线程池
import threading, time def run(n): semaphore.acquire() print('threading in %s' %n) time.sleep(1) semaphore.release() if __name__ == "__main__": semaphore = threading.BoundedSemaphore(5) for i in range(25): t = threading.Thread(target=run,args=(i,)) t.start() while threading.active_count() != 1: pass else: print("All threading is done")