在 Flask 中的路由请求中,我如何触发一个线程启动并让它立即继续到下一行。在下面的代码中,如何在新线程生成后立即打印“已经到下一个”,而不是等待约 10 秒才能完成?
谢谢!
def consumer(searchValue,assignedUniqueID):
print "Searching..."
print "Running thread! Args:", (searchValue, assignedUniqueID)
time.sleep(10)
print "Done!"
@app.route('/_search')
def add_numbers():
assignedUniqueID = str(uuid.uuid4())
Thread(target=consumer(searchValue,assignedUniqueID)).start()
print "Onto the next already"
return jsonify(result="33434443",
assignedUniqueID = assignedUniqueID
)