簡體   English   中英

是否在燒瓶中阻止文件下載?

[英]Non blocking download of file in flask?

我正在使用openstack制作類似服務的投遞箱。 我正在使用flask創建Web界面。 用戶在獲取請求的內容中獲取對象數據。 我正在反復向用戶發送數據。 但是我的Flask應用會停止運行,直到將整個對象下載完畢。 我如何使其不阻塞?

#Returns the json content 
r = swift_account.getObject(container_name, object_name) 
filename = r.headers['X-Object-Meta-Orig-Filename']
#Make a generator so that all the content are not stored at once in memory
def generate():
    for chunk in r.iter_content():
        yield chunk

response = make_response(Response(stream_with_context(generate())))
response.headers['Content-Disposition'] = 'attachment; filename=' + filename
return response

燒瓶以阻塞還是非阻塞方式運行取決於您如何運行。 當您說它阻止時,您如何運行它?

除非它由具有異步功能的東西(例如帶有異步功能的gunicorn)運行,或者至少是針對多個請求的線程模型(例如,帶有mod_wsgi的apache)運行,否則它將無法一次響應多個請求。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM