Skip to content

Instantly share code, notes, and snippets.

@nickscript0
Last active November 6, 2015 13:36
Show Gist options
  • Save nickscript0/7255abf89f73bff47f5e to your computer and use it in GitHub Desktop.
Save nickscript0/7255abf89f73bff47f5e to your computer and use it in GitHub Desktop.
TypeError with async await syntax compared to equivalent @asyncio.coroutine syntax
"""
Was running into the following error with the new async await syntax, where the equivalent @asyncio.coroutine did not give an error.
But this has since resolved, liekly due to an import problem or library version:
...
loop.run_until_complete(hello_world())
File "/usr/local/lib/python3.5/site-packages/asyncio-3.4.3-py3.5.egg/asyncio/base_events.py", line 296, in run_until_complete
future = tasks.async(future, loop=self)
File "/usr/local/lib/python3.5/site-packages/asyncio-3.4.3-py3.5.egg/asyncio/tasks.py", line 516, in async
raise TypeError('A Future or coroutine is required')
TypeError: A Future or coroutine is required
"""
import asyncio
def async_hw():
async def hello_world():
print("Hello World!")
loop = asyncio.get_event_loop()
loop.run_until_complete(hello_world())
loop.close()
def coroutine_hw():
@asyncio.coroutine
def hello_world():
print("Hello World!")
loop = asyncio.get_event_loop()
loop.run_until_complete(hello_world())
loop.close()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment