【发布时间】:2011-12-14 01:42:29
【问题描述】:
我想使用Redis的pubsub特性实现comet,但是pubsub没有超时,所以如果我使用ps.listen(),它会阻塞,即使客户端关闭浏览器。
Greenlet在spawn过程中有超时功能,但我不知道如何组合它们。
Flask 的伪代码:
@app.route('/')
def comet():
rc = redis.Redis()
ps = rc.pubsub()
ps.subscribe('foo')
for item in ps.listen():
if item['type'] == 'message':
return item['data']
# ps.listen() will block, so how to make it timeout after 30 s?
【问题讨论】: