【问题标题】:Python3 on Windows IIS server. Need unbuffered output live outputWindows IIS 服务器上的 Python3。需要无缓冲输出实时输出
【发布时间】:2019-07-06 18:39:44
【问题描述】:

这是我下面的代码,我无法使输出生效,浏览器必须等待。我已经阅读了压缩文件,这适用于在同一服务器上使用 $|=1 的 Perl

#!"C:\Python37\python.exe" -u
import time
import sys


print ("Content-type:text/html\r\n")
print ("<HTML>")

for i in range (30):
    time.sleep(1)
    sys.stdout.flush()
    print ('!')

【问题讨论】:

    标签: python python-3.x iis cgi


    【解决方案1】:

    根据您的描述,我建议您可以尝试使用以下代码通过 python 打印功能禁用缓冲区。

    class Unbuffered(object):
       def __init__(self, stream):
           self.stream = stream
       def write(self, data):
           self.stream.write(data)
           self.stream.flush()
       def writelines(self, datas):
           self.stream.writelines(datas)
           self.stream.flush()
       def __getattr__(self, attr):
           return getattr(self.stream, attr)
    
    import sys
    sys.stdout = Unbuffered(sys.stdout)
    print {Hello}
    

    那么我建议您可以按照下面的答案在 IIS 中禁用此输出缓冲。

    https://www.experts-exchange.com/questions/28964536/Disable-output-buffering-in-IIS8-for-CGI-exe-file-output.html

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2012-10-04
      • 1970-01-01
      • 1970-01-01
      • 2011-01-26
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2014-12-14
      相关资源
      最近更新 更多