Skip to content

Commit 845bea1

Browse files
committed
sim.core: add a warning about async generators on Python <= 3.12
1 parent 2009aba commit 845bea1

File tree

1 file changed

+18
-0
lines changed

1 file changed

+18
-0
lines changed

amaranth/sim/core.py

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -191,6 +191,15 @@ async def testbench(ctx):
191191
which they were added. If two testbenches share state, or must manipulate the design in
192192
a coordinated way, they may rely on this execution order for correctness.
193193
194+
.. warning::
195+
196+
On Python 3.12 and earlier, async generators (:py:`async` functions that also
197+
:py:`yield`) are not cleaned up reliably when the simulator exits. To make sure context
198+
managers or :py:`finally` blocks inside async generators run properly, use Python 3.13
199+
or later. See `PEP-525`_ for more information on async generator finalization.
200+
201+
.. _PEP-525: https://peps.python.org/pep-0525/#finalization
202+
194203
Raises
195204
------
196205
:exc:`RuntimeError`
@@ -248,6 +257,15 @@ async def process(ctx):
248257
:py:`await ctx.tick().sample(...)`. Such state is visible in a waveform viewer,
249258
simplifying debugging.
250259
260+
.. warning::
261+
262+
On Python 3.12 and earlier, async generators (:py:`async` functions that also
263+
:py:`yield`) are not cleaned up reliably when the simulator exits. To make sure context
264+
managers or :py:`finally` blocks inside async generators run properly, use Python 3.13
265+
or later. See `PEP-525`_ for more information on async generator finalization.
266+
267+
.. _PEP-525: https://peps.python.org/pep-0525/#finalization
268+
251269
Raises
252270
------
253271
:exc:`RuntimeError`

0 commit comments

Comments
 (0)