Windows IIS服务器上的Python3。需要无缓冲输出实时输出

2024-04-26 12:51:24 发布

您现在位置:Python中文网/ 问答频道 /正文

这是我下面的代码我无法得到的输出是活的,浏览器必须等待。我已经阅读了压缩方面的内容,并且在同一台服务器上使用$|=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 ('!')

Tags: 代码textimport服务器内容timehtmltype
1条回答
网友
1楼 · 发布于 2024-04-26 12:51:24

根据您的描述,我建议您可以尝试使用下面的代码来禁用带有python print函数的缓冲区。你知道吗

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

相关问题 更多 >