import multiprocessing
import os
import time
def doChorme():
time.sleep(0.1)
def booth(queue,lock):
while True:
i = queue.get()
lock.acquire()
if i > 0:
i = i - 1
queue.put(i)
print("Process:",os.getpid(),"Left %d tickets!" %i)
doChorme()
else:
print("Process:",os.getpid(),"No more tickets!")
lock.release()
i = 10
record = []
lock = multiprocessing.Lock()
queue = multiprocessing.Queue(100)
queue.put(i)
if __name__ == "__main__":
for n in range(5):
process = multiprocessing.Process(target=booth, args=(queue, lock))
process.start()
record.append(process)
queue.close()
for m in record:
m.join()