I'm writing a tornado web server and I'm trying to keep it from blocking on one function.
class TokenHandler(tornado.web.RequestHandler):
@tornado.web.asynchronous
def post(self):
global t
email = self.get_argument("text")
thread = MetaToken.ExeThread(email,t,self._on_response)
thread.start()
#data = t.analyze(email)
def _on_response(self,json):
self.write(json)
self.finish()
Analyze is called in t and can take seconds to complete. I'm ok with that as long as other clients requests can be handled at the same time. This works for the most part but will throw an error on some connections that the stream is closed.