我想使用Redis的发布/订阅功能来实现Comet,但是发布/订阅没有超时功能,所以如果我使用
ps.listen()
,它将被阻塞,即使客户端关闭浏览器也是如此。Greenlet在生成进程时具有超时功能,但我不知道如何将它们组合在一起。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?