Created
March 10, 2015 02:56
-
-
Save cutewalker/b106794cb9017b879af6 to your computer and use it in GitHub Desktop.
run tornado coroutine sync
This file contains hidden or 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
# -*- 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