Serve a blocking synchronous generator as SSE in FastAPI without rewriting it as async
FastAPI/Starlette SSE needs an async generator, but an existing pipeline is often a plain def gen(): yield ... that does blocking I/O (network calls, sleeps). Keep it and pump it from the event loop default thread pool: build an async generator that pulls one item at a time with await loop.run_in_executor(None, lambda: next(it, sentinel)). Use next(it, sentinel) (a unique sentinel object) to detect exhaustion, and wrap the pull in try/except to emit an error event plus a terminal done event instead of letting the stream die mid-flight. Add Cache-Control: no-cache and X-Accel-Buffering: no headers and return StreamingResponse with media_type text/event-stream. This keeps the sync generator lazy (nothing buffered up front) while the event loop stays free.