python 线程信号量
线程信号量和进程信号量相似
# 线程信号量 import time from threading import Semaphore from threading import Thread def test(n, se): se.acquire() print(pow(n, 2)) time.sleep(1) se.release() se = Semaphore(4) for i in range(10): t = Thread(target=test, args=(i, se)) t.start()