Here are two simple RequestHandlers
:
class AsyncHandler(tornado.web.RequestHandler):
@gen.coroutine
def get(self):
while True:
future = Future()
global_futures.add(future)
s = yield future
self.write(s)
self.flush()
class AsyncHandler2(tornado.web.RequestHandler):
@gen.coroutine
def get(self):
for f in global_futures:
f.set_result(str(dt.now()))
global_futures.clear()
self.write("OK")
The first one "subscribes" to the stream, second one delivers message to all subscribers.
The problem is that I cannot have more than a bunch (in my case 5-6) subscribers. As soon as I subscribe more than allowed, the next request to the second method simply hangs.
I assume this is happening due to the first handler not being properly asynchronous. Is that because I am using global object to store list of subscribers?
How can I have more streaming requests open simultaneously, and what is a logical limit?