"asynchronous generator is already running" when using simulator process on Python <= 3.12
bug
(Originally posted to #1590, but in a new issue for visibility and tracking.)
I'm getting RuntimeErrors during simulation when I use a background process that does not complete by the time the simulation ends. Here is a small example:
````.py
import amaranth as am
import amaranth.sim
async def deadline_checker(ctx):
await ctx.tick().repeat(100)
raise RuntimeError('deadline')
m = am.Module()
counter = am.Signal(8)
m.d.sync += counter.eq(counter + 1)
sim = am.sim.Simulator(m)
sim.add_process(deadline_checker)
sim.run()
````
Under Python 3.13.5, this works fine. With Python 3.12.8, I get
````
Exception ignored in: <coroutine object deadline_checker at 0x7f433c8c9f00>
Traceback (most recent call last):
File "/home/agrif/devel/fpga/simulator_aclose.py", line 7, in deadline_checker
File "/home/agrif/devel/fpga/local/nara-env-312/lib/python3.12/site-packages/amaranth/sim/_async.py", line 414, in repeat
RuntimeError: aclose(): asynchronous generator is already running
````
While reading #1590, I was confused by why `aclose(...)` is grumpy, so I dug around. I don't get much from this, but maybe someone else will (or me, later).
* [Python documentation for aclose](https://docs.python.org/3/reference/expressions.html#agen.aclose)
* [first CPython commit with the new behavior (no RuntimeError)](https://github.com/python/cpython/commit/e5c699280deac076cddfef37c8af917a550f6ac3)
关闭于 2026-01-13 9 条评论