2014-10-30 65 views
0

當Web2py變得可用時,它有可能將數據寫入響應中嗎? 例如,我有一個非常長時間運行的函數,它將進度寫入響應。 我希望它的輸出在打印時立即顯示,而不是在整個函數結束時顯示。Web2py中的非緩衝輸出響應

回答

2

退房這個簡單的例子我寫的,它可以幫助,對我的作品

 
#The process to run (print the tablenames) 
def process(db): 
    for tablename in db.tables: 
     for i in range(int(1e5)): pass #Simulate long task for the table 
     yield "%s is ready! <br/>" % tablename #Table result 

#You call this 
def test(): 
    return process(db) #Returning the generator streams the individual results