Repository navigation
fix(python): 0.2.1 — bounded SSE backlog, debounced persistence, gunicorn --preload examples (#74, #77, #86) - #96
Merged
Merged
Conversation
Events read from the stream were handed to the sync thread through an unbounded queue. Each event now counts against a per-stream budget (max_stream_backlog_bytes, default 64 MiB) from when it is read until its task has run. An event that does not fit pauses the reader for up to 250 ms; if it still does not fit, the stream and its queued events are dropped and the client reconnects. The replay merges with the flags held, and events of a replaced stream are never applied. The overflow is reported in get_health() through existing schema-1 fields (reconnect_count, last_error kind network).
With storage, every task that changed flags re-encoded the whole flag set under the client lock and wrote it. Snapshots are now taken at most once per persist_interval_ms (new option, default 500 ms; the first change after a quiet period at once), as a shallow copy under the lock, and encoded (256 flags per step, so other threads get the GIL back) and written after the lock is released. Writes are serialized and numbered: an older snapshot never overwrites a newer one. close() flushes a pending snapshot; a failed write leaves the flags in memory untouched and is retried on the next change or close().
…icorn configs (#86) With gunicorn --preload, AppConfig.ready() runs in the master, so the Django example created its client there and every worker raised CheckgateForkError. flags.get_client() now creates the client on first use in the process that uses it; gunicorn_django.conf.py connects it in post_worker_init and closes it in worker_exit. The Django settings lived in examples/gunicorn.conf.py, which gunicorn loads from the working directory without -c, so the documented Flask command failed to boot from examples/. They are now gunicorn_django.conf.py, next to gunicorn_flask.conf.py (worker_exit closes the Flask client).
…oad (#86) test_examples.py starts each example under gunicorn -w 2 --preload against the fake server, checks that each worker evaluates a flag (by the access log's worker pid), that only the two workers open a stream (none from the master), and that a graceful shutdown closes the client in each worker. CI installs gunicorn, Django and Flask and sets CHECKGATE_REQUIRE_EXAMPLES=1, so these tests cannot skip there.
# Conflicts: # CHANGELOG.md
# Conflicts: # CHANGELOG.md
This was referenced Nov 30, 2026
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.
Python SDK fixes for 0.2.1: #74, #77, #86.
#74: bounded stream backlog
StreamRequest, and events from a replaced stream are ignored.max_stream_backlog_bytes: default 64 MiB, minimum 1 MiB.get_health()as a reconnect plus alast_errorthat names the option. No field was added, so health schema 1 stays aligned with Node.#77: debounced snapshot persistence
persist_interval_ms, default 500. The first change after a quiet period is written at once, then at most one write per interval, always of the newest flags.close()writes the newest snapshot if it changed. A failed write keeps the in-memory state and is retried. The temp-file + rename write is unchanged.#86: Django and Flask examples under gunicorn
--preloadpost_worker_init) and closes it inworker_exit.flags.get_client()checks the process id.gunicorn_django.conf.pyandgunicorn_flask.conf.py, so the documented Flask command boots fromexamples/.test_examples.pyruns both under realgunicorn -w 2 --preload:sdk-pythonjob installs the frameworks and setsCHECKGATE_REQUIRE_EXAMPLES=1, so these tests cannot skip there.Results (macOS):
pytest sdks/python/testspasses 180 on 3.11 and on 3.13, up from 161. The fault-injection suitesdks/conformance/python.mjspasses 27/27. Linux and Windows are covered by CI only.Maintainer decisions:
stream_overflowshealth field would need a schema change shared with the other SDKs.gunicorn.conf.py→gunicorn_django.conf.py,flags.client→flags.get_client()). These are examples, not package API.Refs #74, #77, #86