信号量:
from multiprocessing import Semaphore, Process
from time import sleep
import os
sem = Semaphore(3)
def handle():
print("%d wante"%os.getpid())
sem.acquire()
print("%d do"%os.getpid())
sleep(3)
print("%d finish"%os.getpid())
sem.release()
jods = []
for i in range(5):
p = Process(target=handle)
jods.append(p)
p.start()
for i in jods:
i.join()
print(sem.get_value()) # 获取信号量的值