import threading
import time
def printthread(n):
print n,"---------------->进程创建"
for a in range(4):
print a
time.sleep(1)
print n,"-->进程结束"
sem.release()
if __name__ == "__main__":
maxThread=2
sem=threading.BoundedSemaphore(maxThread)
for a in range(12):
sem.acquire()
i=threading.Thread(target=printthread,args=(a,))
i.start()
print "All thread has create,Wait for all thread exit."
print "All thread exit"
转载于:https://my.oschina.net/shniu/blog/315963