From 2ae0c374fc720d3a4b6f251e98979794ac1ba3b5 Mon Sep 17 00:00:00 2001 From: Satyam Kumar Verman Date: Sun, 23 Nov 2025 04:50:26 +0000 Subject: [PATCH 1/7] gh-141831 --- Doc/library/functools.rst | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/Doc/library/functools.rst b/Doc/library/functools.rst index b2e2e11c0dc414..dfec32be1a80c4 100644 --- a/Doc/library/functools.rst +++ b/Doc/library/functools.rst @@ -50,13 +50,23 @@ The :mod:`functools` module defines the following functions: 479001600 The cache is threadsafe so that the wrapped function can be used in - multiple threads. This means that the underlying data structure will + 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. + .. versionadded:: 3.9 From 5e21e9a11855c37138f4732bea471fc0bb111272 Mon Sep 17 00:00:00 2001 From: Satyam Kumar Verman Date: Sun, 23 Nov 2025 09:00:00 +0000 Subject: [PATCH 2/7] fix-issue-141831-update --- Doc/library/functools.rst | 11 ++--------- 1 file changed, 2 insertions(+), 9 deletions(-) diff --git a/Doc/library/functools.rst b/Doc/library/functools.rst index dfec32be1a80c4..42aeba22ee6da5 100644 --- a/Doc/library/functools.rst +++ b/Doc/library/functools.rst @@ -57,15 +57,8 @@ The :mod:`functools` module defines the following functions: 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. + Call-once behavior is not guaranteed: no locks are held during the function + call, so the same key may be computed multiple times concurrently. .. versionadded:: 3.9 From 813ea97870d1a90db38108b9b0ba5433fb7c3426 Mon Sep 17 00:00:00 2001 From: Satyam Kumar Verman Date: Mon, 24 Nov 2025 02:50:27 +0000 Subject: [PATCH 3/7] updated --- Doc/library/functools.rst | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/Doc/library/functools.rst b/Doc/library/functools.rst index 782425905581e1..65805375d22ca7 100644 --- a/Doc/library/functools.rst +++ b/Doc/library/functools.rst @@ -57,9 +57,15 @@ The :mod:`functools` module defines the following functions: another thread makes an additional call before the initial call has been completed and cached. - Call-once behavior is not guaranteed: no locks are held during the function - call, so the same key may be computed multiple times concurrently. + Call-once behavior is not guaranteed because locks are not held during the + function call.Potentially another call with the same arguments could occur + before the first call has returned. + +<<<<<<< HEAD +======= + +>>>>>>> ad161da7c8 (fixes) .. versionadded:: 3.9 From f591af57de00e03b1285956b64bf760e9593113e Mon Sep 17 00:00:00 2001 From: Raymond Hettinger Date: Mon, 24 Nov 2025 08:24:28 -0600 Subject: [PATCH 4/7] Update functools.rst --- Doc/library/functools.rst | 9 ++------- 1 file changed, 2 insertions(+), 7 deletions(-) diff --git a/Doc/library/functools.rst b/Doc/library/functools.rst index 65805375d22ca7..c2e22dafbf19b1 100644 --- a/Doc/library/functools.rst +++ b/Doc/library/functools.rst @@ -58,14 +58,9 @@ The :mod:`functools` module defines the following functions: 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 - before the first call has returned. + function call. Potentially another call with the same arguments could + occur before the first call has returned. - -<<<<<<< HEAD -======= - ->>>>>>> ad161da7c8 (fixes) .. versionadded:: 3.9 From 9147b8b41b76971fe815a3df48fcf80a95915bed Mon Sep 17 00:00:00 2001 From: Raymond Hettinger Date: Mon, 24 Nov 2025 08:25:46 -0600 Subject: [PATCH 5/7] Update functools.rst --- Doc/library/functools.rst | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Doc/library/functools.rst b/Doc/library/functools.rst index c2e22dafbf19b1..3f9f4c60a9e012 100644 --- a/Doc/library/functools.rst +++ b/Doc/library/functools.rst @@ -50,7 +50,7 @@ The :mod:`functools` module defines the following functions: 479001600 The cache is threadsafe so that the wrapped function can be used in - multiple threads. This means that the underlying data structure will + 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 From 67480349fbba5c05715b614bbfba53c05a373c5a Mon Sep 17 00:00:00 2001 From: Raymond Hettinger Date: Mon, 24 Nov 2025 08:27:17 -0600 Subject: [PATCH 6/7] Update functools.rst --- Doc/library/functools.rst | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Doc/library/functools.rst b/Doc/library/functools.rst index 3f9f4c60a9e012..19bba5ef05c9a0 100644 --- a/Doc/library/functools.rst +++ b/Doc/library/functools.rst @@ -59,7 +59,7 @@ The :mod:`functools` module defines the following functions: Call-once behavior is not guaranteed because locks are not held during the function call. Potentially another call with the same arguments could - occur before the first call has returned. + occur before the first call is completed. .. versionadded:: 3.9 From d821d977733cd19cfc8cb77357f358b845fdc726 Mon Sep 17 00:00:00 2001 From: Raymond Hettinger Date: Mon, 24 Nov 2025 08:29:31 -0600 Subject: [PATCH 7/7] Update functools.rst --- Doc/library/functools.rst | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Doc/library/functools.rst b/Doc/library/functools.rst index 19bba5ef05c9a0..221c0712c7c96a 100644 --- a/Doc/library/functools.rst +++ b/Doc/library/functools.rst @@ -59,7 +59,7 @@ The :mod:`functools` module defines the following functions: Call-once behavior is not guaranteed because locks are not held during the function call. Potentially another call with the same arguments could - occur before the first call is completed. + occur while the first call is still running. .. versionadded:: 3.9