Created
October 11, 2019 16:01
-
-
Save c4urself/a6390d2e044a16ca5deae302a61cca69 to your computer and use it in GitHub Desktop.
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
import asyncio | |
import tornado | |
from tornado import gen, ioloop | |
SLEEPY = 0.2 | |
async def native_coroutine(): | |
print('hi from native') | |
await asyncio.sleep(SLEEPY) | |
@gen.coroutine | |
def decorated_coroutine(): | |
print('hi from tornado decorated coroutine') | |
yield gen.sleep(SLEEPY) | |
@gen.coroutine | |
def decorated_calls_native_coroutine(): | |
print('calling native from decorated...') | |
yield native_coroutine() | |
async def native_calls_decorated_coroutine(): | |
print('calling decorated from native...') | |
await decorated_coroutine() | |
@gen.coroutine | |
def stacked(): | |
print('calling native from decorated (stacked)...') | |
yield native_calls_decorated_coroutine() | |
if __name__ == '__main__': | |
print("TEST 1: regular tornado decorated on tornado loop") | |
ioloop.IOLoop.current().run_sync(decorated_coroutine) | |
print("TEST 2: native asyncio coroutine on tornado loop") | |
ioloop.IOLoop.current().run_sync(native_coroutine) | |
print("TEST 3: decorated calling native on tornado loop") | |
ioloop.IOLoop.current().run_sync(decorated_calls_native_coroutine) | |
print("TEST 4: native asyncio calling decorated on tornado loop") | |
ioloop.IOLoop.current().run_sync(native_calls_decorated_coroutine) | |
print("TEST 5: stacked") | |
ioloop.IOLoop.current().run_sync(stacked) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment