[Python]WSGI, Asynchronous, PEP-333, socket杂博
Posted | archive
def demo_app(environ,start_response):
from StringIO import StringIO
stdout = StringIO()
print >>stdout, "Hello world!"
print >>stdout
h = environ.items(); h.sort()
for k,v in h:
print >>stdout, k,'=',`v`
k=start_response("200 OK", [('Content-Type','text/plain')])
for x in range(1, 100):
k(str(x))
time.sleep(1)
return [stdout.getvalue()]
print >>stdout, "Hello world!"
Python的这种语法非常长见识,很想C++里的语法- f1=f2(); f1(); 这种函数式编程风格是相当的囧
- WSGI要实现异步输出,弄懂了PEP-333还是比较容易的,但是要在服务器端实现间歇性读取POST提交的内容就有点难了。当然这些东西完全超出了WSGI甚至HTTP的 请求 - 响应 模型
- IE is draconian: Clients can’t make more than two HTTP connections to any box/subdomain (per spec).
- 目前在HTTP上模拟socket的Python服务端程序有两个库:Athena,python-cometd
Comments