Skip to content

Instantly share code, notes, and snippets.

View p208p2002's full-sized avatar

Philip p208p2002

View GitHub Profile
@msdrigg
msdrigg / main.py
Created July 14, 2023 21:54
Cancel fastapi route handler on client disconnect
import asyncio
from contextlib import asynccontextmanager
import functools
from typing import Annotated, Any, AsyncContextManager, Awaitable, Callable
from anyio import create_task_group
from anyio.abc import TaskGroup
from fastapi import Request, FastAPI
from fastapi.params import Depends
# Creating this gist for discussion here https://github.com/tiangolo/fastapi/discussions/8805