dry-python / dry-python/returns

ReAwaitable does not support concurrent await call

Abierto
#2,108 1 comentario 0 reacciones 0 asignados Ver en GitHub
bug help wanted
Lenguaje dominante
Python
Estrellas
4.4k
Forks
155
Merge medio
2 h 27 min
PR fusionados (30 d)
22

Descripción

# Bug report

## What's wrong
ReAwaitable cannot be awaited from multiple asyncio tasks simultaneously, and raises exception.
```
/Library/Caches/pypoetry/virtualenvs/project-env/bin/python /Applications/PyCharm.app/Contents/plugins/python-ce/helpers/pycharm/_jb_pytest_runner.py --target test_reawaitable_concurrency.py::test_concurrent_awaitable
Testing started at 16:14 ...
Launching pytest with arguments test_reawaitable_concurrency.py::test_concurrent_awaitable --no-header --no-summary -q in /repos/project/tests/test_primitives/test_reawaitable

============================= test session starts ==============================
collecting ... collected 2 items
Running 2 items in this shard: tests/test_primitives/test_reawaitable/test_reawaitable_concurrency.py::test_concurrent_awaitable[trio], tests/test_primitives/test_reawaitable/test_reawaitable_concurrency.py::test_concurrent_awaitable[asyncio]

test_reawaitable_concurrency.py::test_concurrent_awaitable[trio]
test_reawaitable_concurrency.py::test_concurrent_awaitable[asyncio] /Library/Caches/pypoetry/virtualenvs/project-env/lib/python3.12/site-packages/coverage/inorout.py:524: CoverageWarning: Module project was previously imported, but not measured (module-not-measured)
self.warn(msg, slug="module-not-measured")

ERROR: Coverage failure: total of 1 is less than fail-under=100

============================== 2 failed in 1.29s ===============================
FAILED [ 50%]
tests/test_primitives/test_reawaitable/test_reawaitable_concurrency.py:10 (test_concurrent_awaitable[trio])
+ Exception Group Traceback (most recent call last):
| File "/Library/Caches/pypoetry/virtualenvs/project-env/lib/python3.12/site-packages/_pytest/runner.py", line 341, in from_call
| result: TResult | None = func()
| ^^^^^^
[...multiple frames omitted for brevity...]
| File "/repos/project/tests/test_primitives/test_reawaitable/test_reawaitable_concurrency.py", line 17, in test_concurrent_awaitable
| async with anyio.create_task_group() as tg:
| ^^^^^^^^^^^^^^^^^^^^^^^^^
| File "/Library/Caches/pypoetry/virtualenvs/project-env/lib/python3.12/site-packages/anyio/_backends/_trio.py", line 191, in __aexit__
| return await self._nursery_manager.__aexit__(exc_type, exc_val, exc_tb)
| ExceptionGroup: Exceptions from Trio nursery (1 sub-exception)
+-+---------------- 1 ----------------
| Traceback (most recent call last):
| File "/repos/project/tests/test_primitives/test_reawaitable/test_reawaitable_concurrency.py", line 16, in await_reawaitable
| return await reawaitable
| ^^^^^^^^^^^^^^^^^
| File "/repos/project/project/primitives/reawaitable.py", line 109, in _awaitable
| self._cache = await self._coro
| ^^^^^^^^^^^^^^^^
| RuntimeError: coroutine is being awaited already
+------------------------------------
FAILED [100%]
[... similar traceback omitted for brevity ...]
/Library/Caches/pypoetry/virtualenvs/project-env/lib/python3.12/site-packages/pytest_cov/plugin.py:355: CovFailUnderWarning: Coverage failure: total of 1 is less than fail-under=100
warnings.warn(CovFailUnderWarning(message), stacklevel=1)

```

## How is that should be

ReAwaitable should be awaitable from multiple simultaneous tasks.

## System information

- `returns` version: 0.25.0
- `pytest` version (if any): 8.3.4

Guía de contribución

Abrir la guía de contribución

Evaluación

Este issue todavía no se ha evaluado.

Recibe los nuevos issues en tu correo

Un resumen breve de issues de GitHub para principiantes.