fix: Preserve event delivery with gevent queues - #867
Merged
Conversation
Contributor
posthog-python Compliance ReportDate: 2026-08-12 17:11:44 UTC ✅ All Tests Passed!111/111 tests passed Capture_V1 Tests✅ 94/94 tests passed View Details
Feature_Flags Tests✅ 17/17 tests passed View Details
|
Contributor
|
Reviews (1): Last reviewed commit: "fix: preserve event delivery with gevent..." | Re-trigger Greptile |
5 tasks
Contributor
🦔 ReviewHog reviewed this pull requestFound 1 must fix, 0 should fix, 0 consider. Published 1 finding (view the review). |
Contributor
|
ReviewHog Alpha 🦔 If you find any issues helpful - please reply "valid", "invalid", etc., for evaluation purposes 🙏 |
dustinbyrne
approved these changes
Aug 12, 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.
💡 Motivation and Context
gevent 25.4.1 and later replaces
queue.Queuewhenmonkey.patch_all()runs. The replacement supports the public queue API but does not expose the synchronization attributes used by the PostHog consumer and flush paths. Consumer threads then stop with anAttributeError, flush fails, and captured events remain queued.Fixes #865.
PostHog now checks whether the active queue exposes the synchronization interface required by its consumers. A working standard library queue is used without importing gevent. If gevent replaced the queue, PostHog retrieves the original queue through
gevent.monkey.get_original().If a lane cannot create a usable queue because gevent is unavailable or broken, the SDK logs the specific queue initialization or gevent recovery failure and disables asynchronous capture for that lane. Synchronous capture and queue-independent APIs such as feature flags remain available. A minimal private queue remains only so flush, shutdown, and fork cleanup stay safe on the unavailable lane.
The included example shows capture from gunicorn workers started with
--worker-class gevent --preload.💚 How did you test it?
batch_postwas not called, and the event remained queued.📝 Checklist
If releasing new changes
sampo addto generate a changeset file🤖 Agent context
Autonomy: Human-driven (agent-assisted)
Implemented with Pi under human direction. We compared a copied CPython queue implementation with gevent's supported patch-state APIs. We chose capability detection with
is_object_patched()andget_original()because it preserves the standard library queue type with a smaller maintenance surface. ReviewHog later identified that client-wide disabling would also suppress synchronous capture and feature flags; queue failures are now lane-local with regression coverage for those paths.