-
-
Notifications
You must be signed in to change notification settings - Fork 32.3k
bpo-26180: Fix multiple registration of ForkAwareLocal atfork cleaner #13986
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Conversation
`threading.local` instance `__init__` method is called multiple times, once per thread where the instance is used, but ForkAwareLocal atfork handler needs to be registered just once when its instance is created. If it is registered many times, the registrations bloat `_afterfork_registry` as long as the instance is alive, and can exhaust all memory.
A test for the change would be awesome |
I have added a test |
Added a NEWS blurb. Feel free to edit or squash commits as you see fit. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The change and test look good to me. The only thing that I'm not sure about is whether this is the best fix for the problem: as I mentioned on bpo-26810 I wonder if we could ensure that __init__
is not called multiple times.
|
OK, you convinced me. |
What shall happen next? |
We need a core developer to review your PR. |
Monthly ping. |
threading.local
instance__init__
method is called multiple times, once perthread where the instance is used, but ForkAwareLocal atfork handler needs to be
registered just once when its instance is created. If it is registered many
times, the registrations bloat
_afterfork_registry
as long as the instance isalive, and can exhaust all memory.
https://bugs.python.org/issue26180