From d6388e1c52842161c8302876a98435b077f7ba98 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Rapha=C3=ABl=20Vinot?= Date: Tue, 23 Aug 2016 18:02:29 +0200 Subject: [PATCH] Improve tornado parallel --- misp_modules/__init__.py | 18 +++++++++++++----- 1 file changed, 13 insertions(+), 5 deletions(-) diff --git a/misp_modules/__init__.py b/misp_modules/__init__.py index 525bdc0c..994c7428 100644 --- a/misp_modules/__init__.py +++ b/misp_modules/__init__.py @@ -166,15 +166,23 @@ class ListModules(tornado.web.RequestHandler): self.write(json.dumps(ret)) +@tornado.gen.coroutine +def async_module(request, write_fct): + jsonpayload = request.body.decode('utf-8') + x = json.loads(jsonpayload) + log.debug('MISP QueryModule request {0}'.format(jsonpayload)) + ret = mhandlers[x['module']].handler(q=jsonpayload) + write_fct(json.dumps(ret)) + + class QueryModule(tornado.web.RequestHandler): @tornado.gen.coroutine def post(self): global mhandlers - jsonpayload = self.request.body.decode('utf-8') - x = json.loads(jsonpayload) - log.debug('MISP QueryModule request {0}'.format(jsonpayload)) - ret = mhandlers[x['module']].handler(q=jsonpayload) - self.write(json.dumps(ret)) + try: + yield async_module(self.request, self.write) + except Exception: + log.exception("Someting bad happened.") def main():