Created
April 4, 2015 12:41
-
-
Save grubberr/d6aff353daffbd5bd436 to your computer and use it in GitHub Desktop.
tornado HTTP server for solariat_nlp.classify_content
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/python | |
import json | |
import tornado.gen | |
import tornado.ioloop | |
import tornado.web | |
from futures import ProcessPoolExecutor | |
from solariat_nlp import classify_content | |
def do_work(msg): | |
return json.dumps(classify_content(msg)) | |
class MainHandler(tornado.web.RequestHandler): | |
pool = ProcessPoolExecutor() | |
@tornado.gen.coroutine | |
def post(self): | |
msg = self.request.body | |
result = yield self.pool.submit(do_work, msg) | |
self.write(result) | |
application = tornado.web.Application([ | |
(r'/', MainHandler), | |
]) | |
classify_content("test") # warm-up cache | |
application.listen(8888) | |
tornado.ioloop.IOLoop.instance().start() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment