Repository navigation
fix(flask): isolate event loops for concurrent SSE responses - #182
Open
pcbeingused33 wants to merge 2 commits into
Open
pcbeingused33 wants to merge 2 commits into
pcbeingused33 wants to merge 2 commits into
Conversation
huangjeff5
approved these changes
Nov 30, 2026
huangjeff5
left a comment
Collaborator
There was a problem hiding this comment.
LGTM! Pushed a one-line formatting fix (09b8ee3) adding the blank line after the docstring in _handler.py so ruff format --check passes.
huangjeff5
enabled auto-merge (squash)
November 30, 2026 19:52
Collaborator
|
@pcbeingused33 — pushing that small commit triggered a fresh |
Contributor
Author
|
@googlebot I fixed it. |
This branch has not been deployed
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Concurrent Flask SSE requests to the same flow share the event loop captured when the handler is created. If one WSGI thread is driving the loop, the next stream raises
RuntimeError: This event loop is already runningbefore it can deliver a chunk.Create an event loop inside each WSGI response iterator. Closing the iterator first closes the async stream, which lets the flow finish its cancellation cleanup, then closes the loop.
Tests
python -m pytest -o addopts= -q packages/genkit-flask/tests --tb=shortpassed all 33 tests. The new regression test holds the first invocation open until the second response delivers both its chunk and result, then verifies that the first response also completes. On the base revision, the second response raises the event-loop error.This change was prepared with AI assistance.