import threading
import time
class Producer(threading.Thread):
def __init__(self):
threading.Thread.__init__(self)
def run(self):
global count
while True:
con.acquire()
if count <20:
count += 1
print self.name," Producer product 1,current is %d" %(count)
con.notify()
else:
print self.name,"Producer say box is full"
con.wait()
con.release()
time.sleep(1)
class Consumer(threading.Thread):
def __init__(self):
threading.Thread.__init__(self)
def run(self):
global count
while True:
con.acquire()
if count>4:
count -=4
print self.name,"Consumer consume 4,current is %d" %(count)
con.notify()
else:
con.wait()
print self.name," Consumer say box is empty"
con.release()
time.sleep(1)
count = 0
con = threading.Condition()
def test():
for i in range(1):
a = Consumer()
a.start()
for i in range(1):
b =Producer()
b.start()
if __name__=='__main__':
test()
机械节能产品生产企业官网模板...
大气智能家居家具装修装饰类企业通用网站模板...
礼品公司网站模板
宽屏简约大气婚纱摄影影楼模板...
蓝白WAP手机综合医院类整站源码(独立后台)...苏ICP备2024110244号-2 苏公网安备32050702011978号 增值电信业务经营许可证编号:苏B2-20251499 | Copyright 2018 - 2025 源码网商城 (www.ymwmall.com) 版权所有