1
我注意到python cgi腳本只有在它完成執行後才顯示輸出,有沒有辦法,我可以讓腳本繼續執行並打印結果不斷。我發現如果我在Apache中運行腳本「abc.py」,則輸出會連續顯示(腳本繼續執行),但是從另一個腳本調用腳本不起作用。Python cgi腳本僅在完成後纔在瀏覽器中顯示輸出
下面的代碼: - (abc.py)
import sys, time
#sys.stdout.write('Content-Type: text/html;charset=utf-8\r\n\r\n')
#print '<html><body>'
for i in range(10):
print '<div>%i</div>'%i
sys.stdout.flush()
time.sleep(1)
我想運行從另一個CGI腳本此腳本。現在當我調用這個腳本時(在Apache中使用下面的腳本),輸出僅在完成後才被打印。有沒有辦法解決它。
print 'Content-Type: text/html;charset=utf-8\r\n\r\n'
print '<html><body>'
PIPE = subprocess.PIPE
pd = subprocess.Popen(['abc.py'],
stdout=PIPE, stderr=PIPE)
stdou, stder = pd.communicate()
sys.stdout.write(stdou)
sys.stdout.flush()
你確定這不是等待收盤''