summaryrefslogtreecommitdiffstats
path: root/Lib
diff options
context:
space:
mode:
authorKumar Aditya <59607654+kumaraditya303@users.noreply.github.com>2023-01-20 22:21:40 (GMT)
committerGitHub <noreply@github.com>2023-01-20 22:21:40 (GMT)
commit6954203c9fb7166d3cff8e59ac7e44ddb5bf2fc0 (patch)
tree41996ee8bb45e7e5a4b508d2934281e8a8419df3 /Lib
parent6be2e0e24714fcb69417dad91a1643b0d4063565 (diff)
downloadcpython-6954203c9fb7166d3cff8e59ac7e44ddb5bf2fc0.zip
cpython-6954203c9fb7166d3cff8e59ac7e44ddb5bf2fc0.tar.gz
cpython-6954203c9fb7166d3cff8e59ac7e44ddb5bf2fc0.tar.bz2
[3.9] GH-100892: Fix race in clearing `threading.local` (GH-100922) (#100939)
[3.9] [3.10] GH-100892: Fix race in clearing `threading.local` (GH-100922). (cherry picked from commit 762745a124cbc297cf2fe6f3ec9ca1840bb2e873) Co-authored-by: Kumar Aditya <59607654+kumaraditya303@users.noreply.github.com>. (cherry picked from commit 683e9fe30ecd024f5508b2a33316752870100a96) Co-authored-by: Kumar Aditya <59607654+kumaraditya303@users.noreply.github.com>
Diffstat (limited to 'Lib')
-rw-r--r--Lib/test/test_threading_local.py16
1 files changed, 16 insertions, 0 deletions
diff --git a/Lib/test/test_threading_local.py b/Lib/test/test_threading_local.py
index 5ddb8c4..8b24e3a 100644
--- a/Lib/test/test_threading_local.py
+++ b/Lib/test/test_threading_local.py
@@ -193,6 +193,22 @@ class BaseLocalTest:
self.assertIsNone(wr())
+ def test_threading_local_clear_race(self):
+ # See https://github.com/python/cpython/issues/100892
+
+ try:
+ import _testcapi
+ except ImportError:
+ unittest.skip("requires _testcapi")
+
+ _testcapi.call_in_temporary_c_thread(lambda: None, False)
+
+ for _ in range(1000):
+ _ = threading.local()
+
+ _testcapi.join_temporary_c_thread()
+
+
class ThreadLocalTest(unittest.TestCase, BaseLocalTest):
_local = _thread._local