Skip to content

Instantly share code, notes, and snippets.

@dstufft
Created July 8, 2014 16:34
Show Gist options
  • Save dstufft/32a5348af06a7d622e64 to your computer and use it in GitHub Desktop.
Save dstufft/32a5348af06a7d622e64 to your computer and use it in GitHub Desktop.
import asyncio
def sync(coro):
if asyncio.iscoroutine(coro):
try:
next(coro)
except StopIteration as exc:
return exc.value
else:
return coro
@asyncio.coroutine
def asyncthing():
return "foobar"
print(asyncthing())
print(sync(asyncthing()))
$ python p.py
<generator object coro at 0x101451b88>
foobar
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment