[Async-sig] async generator confusion or bug?
Dima Tisnek
dimaqq at gmail.com
Mon Jun 26 12:25:49 EDT 2017
Hi group,
I'm trying to cross-use an sync generator across several async functions.
Is it allowed or a completely bad idea? (if so, why?)
Here's MRE:
import asyncio
async def generator():
while True:
x = yield
print("received", x)
await asyncio.sleep(0.1)
async def user(name, g):
print("sending", name)
await g.asend(name)
async def helper():
g = generator()
await g.asend(None)
await asyncio.gather(*[user(f"user-{x}", g) for x in range(3)])
if __name__ == "__main__":
asyncio.get_event_loop().run_until_complete(helper())
And the output it produces when ran (py3.6.1):
sending user-1
received user-1
sending user-2
sending user-0
received None
received None
Where are those None's coming from in the end?
Where did "user-0" and "user-1" data go?
Is this a bug, or am I hopelessly confused?
Thanks!
More information about the Async-sig
mailing list