[Bug]: async generator aclose() does not suspend on an await in a finally block
Maintainer antworten meist innerhalb von 1 Tag
Dieses Issue hat noch niemand übernommen.
Bewertung
- Schwierigkeit
- 4/5
- Geschätzter Aufwand
- 3-5 Tage
- Anfängerfreundlichkeit
- 55/100
Rechercherichtung
Start with GraalPy’s async-generator implementation and the CPython test_asyncgen cases named in the report, especially test_async_gen_asyncio_aclose_07, which reproduces the failure. Compare how aclose() handles a yielded value during an await in a finally block with the expected CPython behavior. Done means the yielded value reaches the caller of send(), the generator resumes only on the next send, and the listed tests pass.
Vom Indexierungsmodell aus dem Issue-Text verfasst.
Beschreibung
Describe the bug
When aclose() throws GeneratorExit into an async generator, an await in the generator's finally block does not suspend. GraalPy discards the value that the awaited object yields and resumes the generator at once. The full cleanup then runs inside one send() call on the aclose() awaitable.
CPython passes the yielded value out to the caller of send(), so the event loop sees it. On GraalPy the value never reaches the event loop. With asyncio, any await on a future in a finally block during aclose() fails with RuntimeError: await wasn't used with future.
Operating system
Linux
CPU architecture
x86_64
GraalPy version
GraalPy 3.13.14 (GraalVM CE Native 25.3.4.1), also GraalPy 3.13.14 (GraalVM CE Native 25.4.4.1.1)
JDK version
No response
Context configuration
Minimal reproducer without asyncio:
class Suspend:
def __await__(self):
print(" Suspend: about to yield")
yield "suspended"
print(" Suspend: resumed")
async def agen():
try:
yield 1
finally:
print(" finally: before await")
await Suspend()
print(" finally: after await")
g = agen()
try:
g.__anext__().send(None)
except StopIteration as s:
print("first", s.value)
c = g.aclose()
for i in range(3):
try:
print("send %d ->" % i, repr(c.send(None)))
except StopIteration:
print("send %d -> StopIteration" % i)
break
Output on GraalPy:
first 1
finally: before await
Suspend: about to yield
Suspend: resumed
finally: after await
send 0 -> StopIteration
Reproducer with asyncio:
import asyncio
async def agen():
try:
yield 1
finally:
await asyncio.sleep(0.01)
print("cleanup done")
async def main():
g = agen()
await g.__anext__()
await g.aclose()
asyncio.run(main())
On GraalPy this raises RuntimeError: await wasn't used with future (see the stack trace below).
Steps to reproduce
Minimal reproducer without asyncio:
class Suspend:
def __await__(self):
print(" Suspend: about to yield")
yield "suspended"
print(" Suspend: resumed")
async def agen():
try:
yield 1
finally:
print(" finally: before await")
await Suspend()
print(" finally: after await")
g = agen()
try:
g.__anext__().send(None)
except StopIteration as s:
print("first", s.value)
c = g.aclose()
for i in range(3):
try:
print("send %d ->" % i, repr(c.send(None)))
except StopIteration:
print("send %d -> StopIteration" % i)
break
Output on GraalPy:
first 1
finally: before await
Suspend: about to yield
Suspend: resumed
finally: after await
send 0 -> StopIteration
Reproducer with asyncio:
import asyncio
async def agen():
try:
yield 1
finally:
await asyncio.sleep(0.01)
print("cleanup done")
async def main():
g = agen()
await g.__anext__()
await g.aclose()
asyncio.run(main())
On GraalPy this raises RuntimeError: await wasn't used with future (see the stack trace below).
Expected behavior
Same as CPython 3.13. The first send() on the aclose() awaitable returns the value that the await yields. The generator resumes only on the next send():
first 1
finally: before await
Suspend: about to yield
send 0 -> 'suspended'
Suspend: resumed
finally: after await
send 1 -> StopIteration
The asyncio reproducer prints cleanup done and exits with no error.
Stack trace
Traceback (most recent call last):
File "repro_asyncio.py", line 5, in agen
yield 1
GeneratorExit
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "repro_asyncio.py", line 15, in <module>
asyncio.run(main())
File "<graalpy>/lib/python3.13/asyncio/runners.py", line 196, in run
return runner.run(main)
File "<graalpy>/lib/python3.13/asyncio/runners.py", line 119, in run
return self._loop.run_until_complete(task)
File "<graalpy>/lib/python3.13/asyncio/base_events.py", line 725, in run_until_complete
return future.result()
File "<graalpy>/lib/python3.13/asyncio/futures.py", line 199, in result
raise self._exception.with_traceback(self._exception_tb)
File "<graalpy>/lib/python3.13/asyncio/tasks.py", line 304, in __step_run_and_handle_result
result = coro.send(None)
File "repro_asyncio.py", line 13, in main
await g.aclose()
File "repro_asyncio.py", line 7, in agen
await asyncio.sleep(0.01)
File "<graalpy>/lib/python3.13/asyncio/tasks.py", line 721, in sleep
return await future
File "<graalpy>/lib/python3.13/asyncio/futures.py", line 288, in __await__
raise RuntimeError("await wasn't used with future")
RuntimeError: await wasn't used with future
Additional context
The CPython tests in test_asyncgen that await in finally during aclose() are not in GraalPy's passing list (graalpython/com.oracle.graal.python.test/src/tests/unittest_tags/test_asyncgen.txt): test_async_gen_asyncio_aclose_07, aclose_08, gc_aclose_09 and aclose_12. aclose_07 fails with the same RuntimeError when run on its own.
Found with a Cython test that now excludes this case on GraalPy: https://github.com/cython/cython/pull/8028
- Vorherrschende Sprache
- Python
- Sterne
- 1.7k
- Forks
- 158
- Ø Merge
- 8 Std. 58 Min.
- Gemergte PRs (30 T.)
- 44
Entwicklungsumgebung
Startet den Dev-Container des Projekts im Browser, mit Ihrem eigenen GitHub-Konto.
- Kein Dockerfile und keine Docker-Compose-Datei
- Keine Pull-Request-Vorlage
- Beitragsleitfaden lesen
Erste Schritte
- Lesen Sie das ganze Issue und danach den Beitragsleitfaden des Projekts.
- Schreiben Sie ins Issue, dass Sie es übernehmen — das erspart doppelte Arbeit.
- Forken Sie das Repository und arbeiten Sie in einem Branch.
- Öffnen Sie einen Pull Request, der die Issue-Nummer nennt.
Mehr aus oracle/graalpython
-
[Bug]: `reversed()` on a dict or dict view returns the forward iterator type instead of `dict_reverse*iterator`Evtl. vergeben Ein verknüpfter Pull Request ist offen oder bereits gemergt. Offenbug
Schwierigkeit 2/5 1-3 Stunden Anfängerfreundlichkeit 78/100
oracle/graalpython#1226 ·
Maintainer antworten meist innerhalb von 1 Tag
-
[Bug]: `complex(real, imag)` converts `imag` before rejecting a non-number `real`Evtl. vergeben Ein verknüpfter Pull Request ist offen oder bereits gemergt. Offenbug
Schwierigkeit 2/5 1-3 Stunden Anfängerfreundlichkeit 78/100
oracle/graalpython#1225 ·
Maintainer antworten meist innerhalb von 1 Tag
-
[Bug]: sys.flags.debug is 1 whenever optimization is offEvtl. vergeben @hippi345 hat das vor 3 Tagen übernommen. Offen
Schwierigkeit 2/5 1-3 Stunden Anfängerfreundlichkeit 75/100
oracle/graalpython#1213 ·
Maintainer antworten meist innerhalb von 1 Tag
-
bug
Schwierigkeit 2/5 1-3 Stunden Anfängerfreundlichkeit 74/100
oracle/graalpython#1105 ·
Maintainer antworten meist innerhalb von 1 Tag
-
bug
Schwierigkeit 2/5 1-3 Stunden Anfängerfreundlichkeit 78/100
oracle/graalpython#1102 ·
Maintainer antworten meist innerhalb von 1 Tag
Alle Issues in oracle/graalpython
Ähnliche Issues
-
bug documentation
Schwierigkeit 2/5 1-3 Stunden Anfängerfreundlichkeit 78/100
awslabs/visual-asset-management-system#514 ·
Maintainer antworten meist innerhalb von 1 Tag
-
backend bug spec:REQ-053
Schwierigkeit 2/5 1-3 Stunden Anfängerfreundlichkeit 66/100
nolte/kamerplanter#2547 ·
Maintainer antworten meist innerhalb von 1 Tag
-
Schwierigkeit 2/5 1-3 Stunden Anfängerfreundlichkeit 75/100
EleutherAI/lm-evaluation-harness#4425 ·
Maintainer antworten meist innerhalb von 1 Tag
-
Gemini: respect PLANNING_DISABLED=1 in lifecycle context hooksEvtl. vergeben @AmariAugustin hat das heute übernommen. Offenbug good first issue help wanted
Schwierigkeit 2/5 1-3 Stunden Anfängerfreundlichkeit 87/100
OthmanAdi/planning-with-files#329 · 1 Kommentar ·
Maintainer antworten meist innerhalb von 1 Tag
-
wr.dynamodb.read_items returns [{}] for a single partition value that does not existEvtl. vergeben @auraseb hat das heute übernommen. Offen
Schwierigkeit 2/5 1-3 Stunden Anfängerfreundlichkeit 84/100
aws/aws-sdk-pandas#3520 ·
Maintainer antworten meist innerhalb von 2 Tagen