Created
June 27, 2012 08:27
-
-
Save tomotaka/3002430 to your computer and use it in GitHub Desktop.
tornadooption.py
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
# using https://github.com/tomotaka/msgpack-rpc-python/commit/9a116f7255a5d6c2f773ee48225cd05173b7916b | |
import tornado.web | |
import tornado.gen | |
import tornado.httpserver | |
import tornado.ioloop | |
import msgpackrpc | |
import msgpackrpc.loop | |
class MyHandler(tornado.web.RequestHandler): | |
@tornado.gen.engine | |
@tornado.web.asynchronous | |
def get(self): | |
try: | |
x = int(self.get_argument('x')) | |
y = int(self.get_argument('y')) | |
except: | |
self.write("x and y are not given") | |
else: | |
print "x=" + str(x) + ", y=" + str(y) | |
client = msgpackrpc.Client(msgpackrpc.Address('localhost', 3344), tornado=True) | |
result = yield tornado.gen.Task(client.call_with_callback, "sum", x, y) | |
self.write("x=" + str(x) + ", y=" + str(y) + ", result=" + str(result)) | |
self.finish() | |
if __name__ == '__main__': | |
app = tornado.web.Application( | |
[ | |
(r'/', MyHandler) | |
] | |
) | |
server = tornado.httpserver.HTTPServer(app) | |
server.listen(7788) | |
print "port=7788" | |
tornado.ioloop.IOLoop.instance().start() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment