[3.11] GH-100892: Fix race in clearing threading.local (GH-100922). (#100937)

(cherry picked from commit 762745a124)

Co-authored-by: Kumar Aditya <59607654+kumaraditya303@users.noreply.github.com>
This commit is contained in:
Kumar Aditya 2023-01-11 21:01:48 +05:30 committed by GitHub
parent 1b2459dc64
commit e707671684
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
4 changed files with 73 additions and 19 deletions

View file

@ -3,6 +3,7 @@ import unittest
from doctest import DocTestSuite
from test import support
from test.support import threading_helper
from test.support.import_helper import import_module
import weakref
import gc
@ -197,6 +198,18 @@ class BaseLocalTest:
self.assertIsNone(wr())
def test_threading_local_clear_race(self):
# See https://github.com/python/cpython/issues/100892
_testcapi = import_module('_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