cpython/Lib/test/test_free_threading/test_pwd.py
Alper eddc8c0a1d
gh-116738: Make pwd module thread-safe (#136695)
Make the pwd module functions getpwuid(), getpwnam(), and getpwall() thread-safe. These changes apply to scenarios where the GIL is disabled or in subinterpreter use cases.
2025-07-17 09:16:01 -07:00

33 lines
884 B
Python

import unittest
from test.support import threading_helper
from test.support.threading_helper import run_concurrently
from test import test_pwd
NTHREADS = 10
@threading_helper.requires_working_threading()
class TestPwd(unittest.TestCase):
def setUp(self):
self.test_pwd = test_pwd.PwdTest()
def test_racing_test_values(self):
# test_pwd.test_values() calls pwd.getpwall() and checks the entries
run_concurrently(
worker_func=self.test_pwd.test_values, nthreads=NTHREADS
)
def test_racing_test_values_extended(self):
# test_pwd.test_values_extended() calls pwd.getpwall(), pwd.getpwnam(),
# pwd.getpwduid() and checks the entries
run_concurrently(
worker_func=self.test_pwd.test_values_extended,
nthreads=NTHREADS,
)
if __name__ == "__main__":
unittest.main()