KEMBAR78
Update py sdk exposure event tracking and add docs by efahk · Pull Request #144 · mixpanel/mixpanel-python · GitHub
Skip to content

Conversation

@efahk
Copy link
Contributor

@efahk efahk commented Sep 18, 2025

Submitting the call to track an exposure event on a threadpool was deadlocking in eventlet when threading module is patched.

For now, for more predictability across runtimes, updating calling track directly. Clients can override the consumer with more complex send behavior.
Other updates to use a single thread for polling, adding some public method comments, & some test refactors

GitHub Copilot Summary

This pull request updates the local feature flags evaluation logic and improves documentation, while also making several code quality and performance enhancements. The most significant change is the removal of the thread pool for exposure event tracking in local flags, which simplifies concurrency handling and improves reliability. Additional improvements include adding detailed docstrings to key methods, refactoring for clarity, and updating logging practices.

Local feature flags concurrency and exposure event tracking:

  • Removed the use of ThreadPoolExecutor for exposure event tracking in LocalFeatureFlagsProvider, switching to direct function calls for better reliability and simplicity. This affects both the tracking logic and polling thread management. [1] [2]
  • Changed the polling mechanism for flag definitions from using a thread pool to a dedicated background thread, and improved thread lifecycle management.

Documentation and code clarity:

  • Added and expanded docstrings for public methods in local_feature_flags.py and remote_feature_flags.py, making usage and intent clearer for future maintainers. [1] [2] [3]
  • Refactored method signatures and internal logic for readability, including consistent use of multi-line parameter lists and logging improvements. [1] [2] [3] [4] [5] [6] [7] [8]

Logging and status reporting:

  • Improved logging by replacing errors with warnings where appropriate and switching some info logs to debug for less noise. Also made log messages more descriptive. [1] [2]

Version and changelog updates:

  • Bumped the package version to 5.0.0b2 and updated CHANGES.txt to reflect the new changes. [1] [2]

Remote feature flags cleanup:

  • Removed unused imports and thread pool logic from remote_feature_flags.py for consistency with local flags changes. [1] [2]

Let me know if you want to walk through any of the specific changes in more detail!

@codecov
Copy link

codecov bot commented Sep 19, 2025

Codecov Report

❌ Patch coverage is 96.96970% with 4 lines in your changes missing coverage. Please review.
✅ Project coverage is 93.13%. Comparing base (0f8c84e) to head (3f1b532).
⚠️ Report is 1 commits behind head on master.

Files with missing lines Patch % Lines
mixpanel/flags/local_feature_flags.py 90.24% 2 Missing and 2 partials ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##           master     #144      +/-   ##
==========================================
+ Coverage   92.45%   93.13%   +0.68%     
==========================================
  Files           8        8              
  Lines        1153     1151       -2     
  Branches       76       76              
==========================================
+ Hits         1066     1072       +6     
+ Misses         56       49       -7     
+ Partials       31       30       -1     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@efahk efahk changed the title Update exposure event tracking and add docs Update py sdk exposure event tracking and add docs Sep 24, 2025
Copy link

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull Request Overview

This PR addresses a deadlock issue when tracking exposure events in the Python SDK by removing ThreadPoolExecutor usage and switching to direct synchronous calls for exposure event tracking. The change improves predictability across different Python runtimes, particularly when dealing with patched threading modules like eventlet.

  • Removed ThreadPoolExecutor from both local and remote feature flags providers and switched to direct tracker calls
  • Added comprehensive documentation to public methods in both providers
  • Updated polling implementation to use a dedicated thread instead of executor submission
  • Refactored test structure to use pytest fixtures for better test organization

Reviewed Changes

Copilot reviewed 7 out of 7 changed files in this pull request and generated 2 comments.

Show a summary per file
File Description
mixpanel/flags/types.py Removed custom_executor field from FlagsConfig
mixpanel/flags/remote_feature_flags.py Removed ThreadPoolExecutor usage, added method documentation, switched to direct tracker calls
mixpanel/flags/local_feature_flags.py Replaced ThreadPoolExecutor with threading.Thread for polling, added comprehensive documentation, updated exposure tracking to direct calls
mixpanel/flags/test_remote_feature_flags.py Removed executor shutdown calls from tests
mixpanel/flags/test_local_feature_flags.py Refactored tests to use pytest fixtures and removed executor-related cleanup
mixpanel/init.py Version bump to 5.0.0b2
CHANGES.txt Added changelog entry for the new version

Tip: Customize your code reviews with copilot-instructions.md. Create the file or learn how to get started.

@efahk efahk merged commit 139e398 into master Sep 25, 2025
12 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants