Skip to content

fix: release exited threads' consumers; release 0.1.1 - #20

Merged
lukwam merged 2 commits into
mainfrom
fix/factory-consumer-cleanup
Oct 27, 2026
Merged

lukwam merged 2 commits into
mainfrom
fix/factory-consumer-cleanup

Conversation

@lukwam

@lukwam lukwam commented Oct 27, 2026

Copy link
Copy Markdown
Contributor

Fixes the issues the Everygene agent found while reviewing 0.1.0 for adoption.

Changes

  • Factory consumers no longer pile up. With consumer_factory, the client kept every consumer it had ever made, so each short-lived thread (for example an idle worker that a thread pool retires) added one, and its buffered events waited until the next flush(). Now, when a thread exits, Python releases that thread's Mixpanel instance, and a weakref.finalize hook flushes and releases its consumer. The hook holds only a weak reference to the client. A flush error at that point is logged, since no caller is left to raise to (nothing is logged with on_error="ignore"). As a backup, flush() also flushes and releases any consumer still held for a thread that has exited.
  • A flush error no longer hides the original exception. When a with block raises, a flush error on exit is logged, so the block's own exception propagates. When the block exits normally, a flush error is still raised under on_error="raise".
  • The mixpanel extra is now >=4.0,<6.
  • The __version__ fallback is now 0.0.0 instead of a hardcoded version that would go stale.
  • Release 0.1.1, with a CHANGELOG entry. poetry lock only merged the lock's two typing-extensions entries into one.

Tests

There are 9 new tests, 116 in total. Five of them fail against main:

  • 200 short-lived threads with a buffering consumer leave no consumers held and no events unsent.
  • An error flushing an exited thread's consumer is logged, or skipped with on_error="ignore".
  • Nothing is flushed when the client is disabled.
  • flush() releases an exited thread's consumer that is still referenced.
  • A flush error while leaving a with block that raised doesn't replace the original exception.

The other four guard behavior that already worked: a live thread's consumer is kept, a live thread doesn't keep the client alive, and a flush error still raises when the block exits normally.

🤖 Generated with Claude Code

https://claude.ai/code/session_01CVp1mE8TsPmfiRgNEZPzg5

lukwam and others added 2 commits October 26, 2026 22:15
With consumer_factory, the client held every consumer it had made, and
events buffered by exited threads waited until the next flush(). A
thread's consumer is now flushed and released when the thread exits,
and flush() releases any exited thread's consumer still held.

Leaving a with block that raised no longer replaces its exception with
a flush error under on_error="raise"; the flush error is logged.

Also limit the mixpanel extra to <6, fall back to __version__ 0.0.0,
and release 0.1.1.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Claude-Session: https://claude.ai/code/session_01CVp1mE8TsPmfiRgNEZPzg5
@lukwam
lukwam merged commit cf35e3c into main Oct 27, 2026
5 checks passed
@lukwam
lukwam deleted the fix/factory-consumer-cleanup branch October 27, 2026 02:49
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.

1 participant