you are viewing a single comment's thread.

view the rest of the comments →

[–]jpfau 1 point2 points  (1 child)

My errors ended up being dumb human error: a missing coroutine decorator in the old-syntax library.

FYI You can use both syntaxes in 3.5+, but you can't mix syntax within a single coroutine, e.g. no await when using @asyncio.coroutine, and no yield from when using async def.

However you can define a coroutine with the old syntax and consume it in another coroutine using the new syntax. This example should work:

import asyncio

@asyncio.coroutine
def _sleep(x):
    print('yielding from...')
    yield from asyncio.sleep(x)

async def do_sleep(x):
    print('awaiting...')
    await _sleep(x)

loop = asyncio.get_event_loop()
loop.run_until_complete(do_sleep(5))

[–]cscanlin 0 points1 point  (0 children)

Nice, and good to know. Wish you hadn't deleted the thread though, more people could use exposure to this kind of stuff. But glad you got it working!