I use coroutines based on the py3.4 generator, and in several places I fetched them, just having one coroutine call return inner_coroutine()
(as in the example below). However, I am now converting them to use my own coroutines py3.5, and I found that it no longer works, since the internal coroutine does not start (see the output from the example below). To start the internal internal coroutine, I need to use return await inner_coroutine()
instead of the original return inner_coroutine()
.
I expected that linking my own coroutines would work the same way as on the basis of the generator, and could not find any documentation that said otherwise. Am I missing something or is this the actual limitation of native coroutines?
import asyncio
@asyncio.coroutine
def coro():
print("Inside coro")
@asyncio.coroutine
def outer_coro():
print("Inside outer_coro")
return coro()
async def native_coro():
print("Inside native_coro")
async def native_outer_coro():
print("Inside native_outer_coro")
return native_coro()
loop = asyncio.get_event_loop()
loop.run_until_complete(outer_coro())
loop.run_until_complete(native_outer_coro())
:
Inside outer_coro
Inside coro
Inside native_outer_coro
foo.py:26: RuntimeWarning: coroutine 'native_coro' was never awaited
loop.run_until_complete(native_outer_coro())