Repository navigation
fix(generator): makes generator state fork- and thread-safe - #73
Merged
Merged
Conversation
Replaces the os.register_at_fork hook and WeakSet registry with a per-process state bundle that the first generate() call in a new process rebuilds once, covering forks that skip Python's fork hooks (uWSGI default mode). Switches to re-entrant locks, adds Cuid.__deepcopy__, adds 3.15t to CI, and adds free-threading regression guards.
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.
Summary
Cuid,create_id(),cuid_wrapper(), andutils.create_counter()thread-safe with re-entrant locks (so a signal handler or finalizer that generates an ID can't deadlock): on free-threaded 3.14t the unlocked counter returned ~323k–380k unique values from 1.6M calls and the lazy default generator was built up to 8 times per first-call race (also on GIL builds)os.register_at_fork: eachCuidkeeps per-process state that the firstgenerate()in a new process rebuilds exactly once (fresh lock, reseeded RNG, counter, and child-PID fingerprint), covering forks that skip Python's fork hooks such as uWSGI's default mode;copy.deepcopy()now returns an independent generator3.14tand3.15tCI jobs and theFree Threading :: 3 - Stableclassifier, plus regression guards that fail if a CI version ≥ 3.14 lacks atjob or a free-threaded run has the GIL re-enabled