External futures can't be awaited across feeds within the same session
Author: davidhewittCreated Sep 17, 2026Updated Sep 17, 2026
Ran into this reviewing #822
The PR proposes making each feed fully close external futures. I wonder if we should instead support the other direction; it should be valid to keep futures open across feeds:
import asyncio
from pydantic_monty import AsyncMonty
async def main():
ready = asyncio.Event()
async def fetch():
await ready.wait()
return 42
async with AsyncMonty() as pool:
async with pool.checkout() as session:
await session.feed_run('f = fetch()', external_lookup={'fetch': fetch})
ready.set()
print(await session.feed_run('await f'))
asyncio.run(main())Unfortunately, at present the second feed will raise with
RuntimeError: No pending async tasks but ResolveFutures requestedSource: pydantic/monty