龙卷风长时间轮询请求 [英] Tornado long polling requests
问题描述
以下是我的问题中最简单的示例:
Below is the most simple example of my issue:
发出请求时,它将打印Request via GET <__main__.MainHandler object at 0x104041e10>
,然后该请求将保持打开状态.好的!但是,当您发出另一个请求时,直到第一个连接完成,它才调用MainHandler.get
方法.
When a request is made it will print Request via GET <__main__.MainHandler object at 0x104041e10>
and then the request will remain open. Good! However, when you make another request it does not call the MainHandler.get
method until the first connection has finished.
如何在使多个请求保持长时间轮询的同时将多个请求带入get
方法.我通过每个请求传递参数,这些请求将通过redis从pub/sub获得不同的结果.问题是我一次只能建立一个连接.怎么了?为什么这会阻止其他请求?
How can I get multiple requests into the get
method while having them remain long-polling. I'm passing arguments with each request that will get different results from a pub/sub via redis. Issue is that I only get one connection in at a time. Whats wrong? And why is this blocking other requests?
import tornado.ioloop
import tornado.web
import os
class MainHandler(tornado.web.RequestHandler):
@tornado.web.asynchronous
def get(self):
print 'Request via GET', self
if __name__ == '__main__':
application = tornado.web.Application([
(r"/", MainHandler)])
try:
application.listen(int(os.environ.get('PORT', 5000)))
tornado.ioloop.IOLoop.instance().start()
except KeyboardInterrupt:
tornado.ioloop.IOLoop.instance().stop()
左图:如上所述.这些请求未按照右图中请求的方式进行处理. 右图,我需要由RequestHandler处理请求(a-d),然后等待发布/订阅发布它们的数据.
Diagram Left: As described in issue above. The requests are not handled in the fashion requested in right diagram. Diagram on the right I need the requests (a-d) to be handled by the RequestHandler and then wait for the pub/sub to announce their data.
a b c d
+ + + + ++ a b c d
| | | | || + + + +
| | | | || | | | |
| | | | || | | | |
| | | | || | | | |
| v v v || | | | |
+---|-----------------------------+ || +-----|----|---|---|------------------+
| | | || | | | | | |
| + RequestHandler| || | + + + + RequestHan. |
| | | || | | | | | |
+---|-----------------------------+ || +-----|----|---|---|------------------+
+---|-----------------------------+ || +-----|----|---|---|------------------+
| | | || | | | | | |
| + Sub/Pub Que | || | v + v v Que |
| | | || | | |
+---|-----------------------------+ || +----------|--------------------------+
+---|-----------------------------+ || +----------|--------------------------+
| || |
| Finished || | Finished
v || v
||
||
||
||
||
||
||
++
如果这是另一种编程语言可以实现的,请告诉我.
If this is accomplishable with another programming language please let me know.
谢谢您的帮助!