In my python file I have two handler classes: MainHandler(tornado.web.RequestHandler) and WebSocketHandler(tornado.web.WebSocketHandler). In the MainHandler class I do the following code in the get method:
class MainHandler(tornado.web.RequestHandler):
#some code
def get(self):
#some code
mainHandler_dict[chan] = self
await self.finish() #line of code that would do the waiting somehow
So I store the request in a global dictionary so I can call request.write()
and request.finish()
in the on_message
method of the WebSocketHandler class:
class WebSocketHandler(tornado.websocket.WebSocketHandler):
def on_message(self, message):
#some code
request.write(body)
request.finish()
I get the "request" variable from the global dictionary and try to call write(), but the following error occurs: RuntimeError: Cannot write() after finish()
I think finish()
is being automatically called after the end of the get method in the MainHandler class.
So is there a way for the requestHandler to keep on "waiting" while I don't call the request.finish()
somewhere through the file?