Use WeakKeyDictionary for WRITE_LOCKS to prevent file object leaks#807
Merged
hynek merged 3 commits intohynek:mainfrom May 2, 2026
Merged
Use WeakKeyDictionary for WRITE_LOCKS to prevent file object leaks#807hynek merged 3 commits intohynek:mainfrom
hynek merged 3 commits intohynek:mainfrom
Conversation
Open
1 task
File objects registered in WRITE_LOCKS were never released, causing a memory leak in long-running processes that open many log files (e.g., task executors creating a per-task BytesLogger or WriteLogger). WeakKeyDictionary stores keys as weak references, so entries expire automatically when the last strong reference to a file object is dropped — no manual cleanup needed. Closes hynek#806 (no need to expose it, we tidy it up correctly ourselves)
9 tasks
hynek
approved these changes
May 2, 2026
Owner
hynek
left a comment
There was a problem hiding this comment.
Awesome, thank you! I knew there had to be some API but didn't get around to check.
|
@hynek cool! Do you happen to know when a release with this change will be available? |
Owner
|
I want to release the very overdue 26.1.0 ASAP, but I need to work myself through the list of PRs, so I cannot make any promises on the timeline, sorry. |
|
ok thanks! |
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.
File objects registered in WRITE_LOCKS were never released, causing a
memory leak in long-running processes that open many log files (e.g.,
task executors creating a per-task BytesLogger or WriteLogger).
WeakKeyDictionary stores keys as weak references, so entries expire
automatically when the last strong reference to a file object is
dropped — no manual cleanup needed.
Closes #806 (no need to expose it, we tidy it up correctly ourselves)
A test script to show that WeakKeyDict works:
Pull Request Check List
mainbranch.api.py.docs/api.rstby hand.versionadded,versionchanged, ordeprecateddirectives..rstand.mdfiles is written using semantic newlines.