2014-10-22 73 views
0

我正在使用openstack來製作一個類似服務的下拉框。我正在使用燒瓶製作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 

回答

0

燒瓶是否作爲阻塞或非阻塞運行取決於您如何運行它。當你說它阻止,你如何運行它?

除非它是由具有async功能的異步功能運行,或者至少有一個針對多個請求的線程模型,比如使用mod_wsgi的apache,那麼它將無法一次響應多個請求。

+0

謝謝丹尼。我把我的服務器作爲線程運行,現在它的工作非常完美。現在我知道Flask既不阻塞也不阻塞,它在運行時運行。 – 2014-10-23 17:15:27