Skip to content

Conversation

@SkvProgrammer
Copy link
Contributor

@SkvProgrammer SkvProgrammer commented Nov 23, 2025

updating functools documentation

changes made:Clarified threading behavior in lru_cache.

from:

The cache is threadsafe so that the wrapped function can be used in
multiple threads.  This means that the underlying data structure will
remain coherent during concurrent updates.

It is possible for the wrapped function to be called more than once if
another thread makes an additional call before the initial call has been
completed and cached.

to

The cache is threadsafe so that the wrapped function can be used in
multiple threads.  This means that the underlying data structure will
remain coherent during concurrent updates.

It is possible for the wrapped function to be called more than once if
another thread makes an additional call before the initial call has been
completed and cached.

In particular, when the same key is computed concurrently in multiple
threads, each thread may execute the wrapped function independently
before the first result is stored in the cache. As a consequence, the
return values from these concurrent calls may be distinct objects even
though they correspond to the same cache key.

This behavior means that ``lru_cache`` should not be relied upon for
singleton object creation or other scenarios requiring that only one
instance be constructed for a given key without external synchronization.


📚 Documentation preview 📚: https://cpython-previews--141869.org.readthedocs.build/

@python-cla-bot
Copy link

python-cla-bot bot commented Nov 23, 2025

All commit authors signed the Contributor License Agreement.

CLA signed

@rhettinger
Copy link
Contributor

This is a lot of extra text and is distracting from the core uses of lru_cache. Can you make a more succinct edit perhaps just saying that call-once behavior is not guaranteed because no locks are held during the function call.

@rhettinger rhettinger self-assigned this Nov 23, 2025
@SkvProgrammer
Copy link
Contributor Author

I have updated it , please check

completed and cached.

Call-once behavior is not guaranteed because locks are not held during the
function call.Potentially another call with the same arguments could occur
Copy link
Contributor

Choose a reason for hiding this comment

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

Add a space after the period.



<<<<<<< HEAD
=======
Copy link
Contributor

Choose a reason for hiding this comment

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

Remove conflict markers.

@bedevere-app
Copy link

bedevere-app bot commented Nov 24, 2025

A Python core developer has requested some changes be made to your pull request before we can consider merging it. If you could please address their requests along with any other requests in other reviews from core developers that would be appreciated.

Once you have made the requested changes, please leave a comment on this pull request containing the phrase I have made the requested changes; please review again. I will then notify any core developers who have left a review that you're ready for them to take another look at this pull request.

@rhettinger rhettinger enabled auto-merge (squash) November 24, 2025 14:31
@rhettinger rhettinger merged commit 9346e22 into python:main Nov 24, 2025
27 of 28 checks passed
@github-project-automation github-project-automation bot moved this from Todo to Done in Docs PRs Nov 24, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

docs Documentation in the Doc dir skip news

Projects

Status: Done

Development

Successfully merging this pull request may close these issues.

3 participants