Skip to main content
 首页 » 编程设计

python之是否有一个 wsgi 服务器可以进行渐进式传输编码 : chunked

2025年05月04日8shanyou

是否有可以执行渐进式传输编码的 wsgi 网络服务器:分块? IE。它应该在从应用程序接收到内容时将其写入套接字。

我用 wsgiref、waitress 和 gunicorn 尝试了以下应用程序。他们都没有立即写下 'First bit of content'..

import time 
 
def app(environ, start_response): 
    start_response('200 OK', [('Content-Type', 'text/plain')]) 
    def content(): 
        yield 'First bit of content\n' 
        time.sleep(5) 
        yield 'Second bit of content' 
    return content() 

请您参考如下方法:

感谢 Jon 的提示,我让它在女服务员中工作:

import time 
 
 
def app(environ, start_response): 
 
    start_response('200 OK', [('Content-Type', 'text/plain')]) 
 
    def content(): 
        yield ''.join(('First bit of content', '.' * 18000, '\n')) 
        time.sleep(5) 
        yield 'Second bit of content' 
    return content() 
 
import waitress 
waitress.serve(app, host='0.0.0.0', port=8080) 

Waitress 会在达到 18000 字节时发送数据(这也可以在创建服务器时配置。)