无缘无故,即使我在队列中放了一些项目,它仍然显示我
Queue.empty() == True
工人们正在使用一种与烧瓶法不同的工艺。如果我试图使用一些Flask sub将项目添加到队列中,然后检查队列是否不是空的(使用另一个Flask sub),我可以看到队列已满。但是我仍然从workerJob
子节点得到“queue is empty”
from multiprocessing import Queue, Process, Pool
imgQueue = Queue()
@app.route("/send", methods=["POST"])
def sendToQueue():
# global imgQueue
imgLocation = request.headers.get('fileLocation')
nImage = request.data
imgQueue.put({"location": imgLocation,
"image": nImage})
return "ok"
def workerJob(q):
while True:
print(q.empty())
if (not q.empty()):
itemFromQueue = q.get()
print(str(type(itemFromQueue)))
print(itemFromQueue["location"])
print(itemFromQueue["image"])
else:
print("Queue empty")
time.sleep(3)
def startWorkers():
global imgQueue
while True:
procs = [Process(target=workerJob, args=(imgQueue,)) for i in range(1)]
for p in procs:
p.start()
def flaskThread():
app.run(host='0.0.0.0', threaded=True)
if __name__ == '__main__':
# app.run(host='0.0.0.0', threaded=True)
flaskProcess = Process(target=flaskThread, args=())
flaskProcess.start()
workerProcess = Process(target=startWorkers, args=())
workerProcess.start()
目前没有回答
相关问题 更多 >
编程相关推荐