Skip to content
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

GH-93179: Document the thread safety of functools.lru_cache #96101

Merged
merged 1 commit into from
Aug 21, 2022

Conversation

rhettinger
Copy link
Contributor

@rhettinger rhettinger commented Aug 19, 2022

@rhettinger rhettinger added docs Documentation in the Doc dir skip news needs backport to 3.11 only security fixes labels Aug 19, 2022
@rhettinger rhettinger merged commit eea8f42 into python:main Aug 21, 2022
@miss-islington
Copy link
Contributor

Thanks @rhettinger for the PR 🌮🎉.. I'm working now to backport this PR to: 3.11.
🐍🍒⛏🤖

@miss-islington
Copy link
Contributor

Sorry, @rhettinger, I could not cleanly backport this to 3.11 due to a conflict.
Please backport using cherry_picker on command line.
cherry_picker eea8f42deddb3b6fec80984e7557b1f0c4578b62 3.11

@1st
Copy link

1st commented Aug 26, 2022

Sorry, but we have an issue with the @lru_cache as it doesn't work like a singleton like we expected.

In the code it has thread lock, but problem that it's done outside of the function call.

with lock:
    # ...        
result = user_function(*args, **kwds)

image

As result, we have issue with threads - function call made multiple times, but we expected that this @lru_cache decorator will ensure that we receive exactly cached value that will be calculated only once.

Currently I'm in a doubt, should we create our own version of the decorator that will have the lock over the whole @lru_cache. Maybe you did it by purpose, by not having the function call inside the lock?

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 needs backport to 3.11 only security fixes skip news
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants