import threading
import time
from queue import Queue
class Pro(threading.Thread):
def run(self):
global qu
count=0
while True:
if qu.qsize()<1000:
for i in range(100):
count+=1
msg="生成产品"+str(count)
qu.put(msg)
print(msg)
time.sleep(1)
class Con(threading.Thread):
def run(self):
global qu
while True:
if qu.qsize()>100:
for i in range(3):
msg=self.name+"消费了"+qu.get()
print(msg)
time.sleep(1)
if __name__=="__main__":
qu=Queue
for i in range(500):
qu.put("初始产品"+str(i),)
for i in range(2):
p=Pro()
p.start()
for i in range(5):
c=Con()
c.start()
代码跟老师的一样,为什么会报这样的错??????????
Traceback (most recent call last):
File "C:/Users/齐泉/PycharmProjects/1/test2.py", line 28, in <module>
qu.put("初始产品"+str(i))
TypeError: put() missing 1 required positional argument: 'item'
Process finished with exit code 1