following this discussion
https://discord.com/channels/919193495116337154/1256638718236823593
we could make the below mvce simpler and catch a HTTPDisconnect
instead of forcing the user to use anyio CancelledError
(see @provinzkraut answer here: https://discord.com/channels/919193495116337154/1256638718236823593/1256895758255521804)
No response
@get("/foo")
async def foo(db_pool: Pool, db_connection: Connection) -> Stream:
stream_id = await db_connection.fetchval(
"""insert into toto(stream) values ('') returning id"""
)
print(stream_id)
async def chunks(num, stream_id):
async with db_pool.acquire() as conn:
try:
for i in range(num):
chunk = f"chunk #{i}\n"
yield chunk
await asyncio.sleep(0.5)
update = await conn.execute(
f"update toto set stream = '{i}' where id={stream_id}"
)
print(update)
except CancelledError as e:
print(str(e))
with CancelScope(shield=True):
delete = await conn.execute(f"delete from toto where id={id}")
print(delete)
raise
finally:
print("end")
return Stream(chunks(10, stream_id))
1. Go to '...'
2. Click on '....'
3. Scroll down to '....'
4. See error
"![SCREENSHOT_DESCRIPTION](SCREENSHOT_LINK.png)"
No response
2.9.0
Pay now to fund the work behind this issue.
Get updates on progress being made.
Maintainer is rewarded once the issue is completed.
You're funding impactful open source efforts
You want to contribute to this effort
You want to get funding like this too