mirror of
https://github.com/python/cpython.git
synced 2025-11-01 14:11:41 +00:00
[3.14] gh-116738: Make grp module thread-safe (GH-135434) (#136658)
gh-116738: Make grp module thread-safe (GH-135434)
Make grp module methods getgrgid() and getgrnam() thread-safe when the GIL is disabled and getgrgid_r()/getgrnam_r() C APIs are not available.
---------
(cherry picked from commit 9363703bd3)
Co-authored-by: Alper <alperyoney@fb.com>
Co-authored-by: Kumar Aditya <kumaraditya@python.org>
This commit is contained in:
parent
bbbbb2e2d1
commit
55eaaab8a4
7 changed files with 115 additions and 46 deletions
|
|
@ -248,3 +248,27 @@ def requires_working_threading(*, module=False):
|
|||
raise unittest.SkipTest(msg)
|
||||
else:
|
||||
return unittest.skipUnless(can_start_thread, msg)
|
||||
|
||||
|
||||
def run_concurrently(worker_func, nthreads, args=(), kwargs={}):
|
||||
"""
|
||||
Run the worker function concurrently in multiple threads.
|
||||
"""
|
||||
barrier = threading.Barrier(nthreads)
|
||||
|
||||
def wrapper_func(*args, **kwargs):
|
||||
# Wait for all threads to reach this point before proceeding.
|
||||
barrier.wait()
|
||||
worker_func(*args, **kwargs)
|
||||
|
||||
with catch_threading_exception() as cm:
|
||||
workers = [
|
||||
threading.Thread(target=wrapper_func, args=args, kwargs=kwargs)
|
||||
for _ in range(nthreads)
|
||||
]
|
||||
with start_threads(workers):
|
||||
pass
|
||||
|
||||
# If a worker thread raises an exception, re-raise it.
|
||||
if cm.exc_value is not None:
|
||||
raise cm.exc_value
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue