@app.get("/sse")def sse(): if "text/event-stream" not in request.accept_mimetypes: abort(400) def send_events(): nonlocal variable while True: event_binary = b'' if condition: data = ... _event = ... event = ServerSentEvent(data, _event) event_binary = event.encode() yield event_binary time.sleep(0.1) response = Response( send_events(), mimetype="text/event-stream", ) response.timeout = None return response