Skip to content

Instantly share code, notes, and snippets.

@davebshow
Last active August 29, 2015 14:15
Show Gist options
  • Save davebshow/f5668437398afa749f37 to your computer and use it in GitHub Desktop.
Save davebshow/f5668437398afa749f37 to your computer and use it in GitHub Desktop.
import asyncio
import json
from tornado import escape, gen
from tornado.web import RequestHandler, Application, url
from tornado.platform.asyncio import AsyncIOMainLoop
from gizmo import AsyncGremlinClient
class GremlinHandler(RequestHandler):
@gen.coroutine
def get(self):
gc = AsyncGremlinClient(uri='ws://localhost:8182/')
consumer = lambda x: x["result"]["data"]
yield from gc.task(gc.send_receive, "g.V().values(n)",
bindings={"n": "name"}, consumer=consumer)
while not gc.messages.empty():
message = yield from gc.messages.get()
message = json.dumps(message)
self.write(message)
def make_app():
return Application([
url(r"/", GremlinHandler),
])
def main():
app = make_app()
# Must create IOLoop before calling app.listen.
AsyncIOMainLoop().install()
app.listen(8888)
asyncio.get_event_loop().run_forever()
if __name__ == '__main__':
print("Starting server at http://localhost:8888/")
main()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment