[issue30773] async generator receives wrong value when shared between coroutines

Dima Tisnek report at bugs.python.org
Mon Jun 26 14:55:33 EDT 2017


New submission from Dima Tisnek:

MRE

```
import asyncio


async def generator():
    while True:
        x = yield 42
        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())
```

Produces output:

```
sending user-0
received user-0
sending user-1
sending user-2
received None
received None
```

Expected output (some variance allowed):

```
sending user-0
received user-0
sending user-1
sending user-2
received user-1
received user-2
```

Initial report / discussion: https://mail.python.org/pipermail/async-sig/2017-June/000293.html

----------
components: asyncio
messages: 296931
nosy: Dima.Tisnek, yselivanov
priority: normal
severity: normal
status: open
title: async generator receives wrong value when shared between coroutines
type: behavior
versions: Python 3.6

_______________________________________
Python tracker <report at bugs.python.org>
<http://bugs.python.org/issue30773>
_______________________________________


More information about the Python-bugs-list mailing list