Skip to content

Instantly share code, notes, and snippets.

@cutewalker
Created March 10, 2015 02:56
Show Gist options
  • Save cutewalker/b106794cb9017b879af6 to your computer and use it in GitHub Desktop.
Save cutewalker/b106794cb9017b879af6 to your computer and use it in GitHub Desktop.
run tornado coroutine sync
# -*- coding: utf-8 -*-
from tornado import gen
from tornado.ioloop import IOLoop
def run_sync(func, *sub, **kw):
result = func(*sub, **kw)
if not gen.is_future(result):
return result
@gen.coroutine
def foo():
res = yield result
raise gen.Return(res)
return IOLoop.current().run_sync(foo)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment