cv2.imread 正在阻塞流量
cv2.imread is blocking flow
我正在尝试使用 cv2.imread()
读取图像,但流程只是阻塞在那里并且从未 returns,尝试读取已经存在的文件但遇到了同样的问题,我不确定是什么原因是
@app.route('/api/upload', methods=['GET', 'POST'])
def upload_file():
print('request method is {}'.format(request.method))
if request.method == 'POST':
# check if the post request has the file part
if 'file' not in request.files:
print('file not in request.files')
return redirect(request.url)
file = request.files['file']
if file.filename == '':
print('filename is {}'.format(file.filename))
return redirect(request.url)
print(file and allowed_file(file.filename))
if file and allowed_file(file.filename):
print('receiving ... ', file.filename)
filename = secure_filename(file.filename)
ts = int(time.time())
file_name = file_name_template.format(ts, filename)
print(file_name)
filePath = os.path.join(app.root_path, app.config['UPLOAD_FOLDER'], file_name)
file.save(filePath)
print('reading image')
cv2.imread(filePath)
return 'done' #never executed
注意:这是 运行 在 WAMP server
+ WSGI
上的烧瓶应用程序
我相信这个问题已经在另一个 posting. Also see http://blog.rtwilson.com/how-to-fix-flask-wsgi-webapp-hanging-when-importing-a-module-such-as-numpy-or-matplotlib/ 中得到了回答。
基本上,它没有使用主解释器来 运行 cv2.imread,这在子解释器中 运行 是不正确的。
我正在尝试使用 cv2.imread()
读取图像,但流程只是阻塞在那里并且从未 returns,尝试读取已经存在的文件但遇到了同样的问题,我不确定是什么原因是
@app.route('/api/upload', methods=['GET', 'POST'])
def upload_file():
print('request method is {}'.format(request.method))
if request.method == 'POST':
# check if the post request has the file part
if 'file' not in request.files:
print('file not in request.files')
return redirect(request.url)
file = request.files['file']
if file.filename == '':
print('filename is {}'.format(file.filename))
return redirect(request.url)
print(file and allowed_file(file.filename))
if file and allowed_file(file.filename):
print('receiving ... ', file.filename)
filename = secure_filename(file.filename)
ts = int(time.time())
file_name = file_name_template.format(ts, filename)
print(file_name)
filePath = os.path.join(app.root_path, app.config['UPLOAD_FOLDER'], file_name)
file.save(filePath)
print('reading image')
cv2.imread(filePath)
return 'done' #never executed
注意:这是 运行 在 WAMP server
+ WSGI
我相信这个问题已经在另一个 posting. Also see http://blog.rtwilson.com/how-to-fix-flask-wsgi-webapp-hanging-when-importing-a-module-such-as-numpy-or-matplotlib/ 中得到了回答。
基本上,它没有使用主解释器来 运行 cv2.imread,这在子解释器中 运行 是不正确的。