GH-100892: Fix race in clearing threading.local (#100922)

This commit is contained in:
Kumar Aditya 2023-01-11 16:03:31 +05:30 committed by GitHub
parent 847d7708ba
commit 762745a124
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
4 changed files with 70 additions and 15 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
# Modules under test
@ -196,6 +197,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