Skip to content

Instantly share code, notes, and snippets.

@tomotaka
Created June 27, 2012 08:27
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save tomotaka/3002430 to your computer and use it in GitHub Desktop.
Save tomotaka/3002430 to your computer and use it in GitHub Desktop.
tornadooption.py
# 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