8000 BUG: fix race initializing legacy dtype casts by charris · Pull Request #28321 · numpy/numpy · GitHub
[go: up one dir, main page]

Skip to content

BUG: fix race initializing legacy dtype casts #28321

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 15 commits into from
Feb 11, 2025
Merged
Changes from 1 commit
Commits
8000 File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
MAINT: refactor run_threaded to use a try/finally block
  • Loading branch information
ngoldbaum authored and charris committed Feb 11, 2025
commit 425d162c15cc9cd0879269a96d8971ec1f632906
45 changes: 26 additions & 19 deletions numpy/testing/_private/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -2690,25 +2690,32 @@ def run_threaded(func, max_workers=8, pass_count=False,
prepare_args=None):
"""Runs a function many times in parallel"""
for _ in range(outer_iterations):
with (concurrent.futures.ThreadPoolExecutor(max_workers=max_workers)
as tpe):
if prepare_args is None:
args = []
else:
args = prepare_args()
if pass_barrier:
barrier = threading.Barrier(max_workers)
args.append(barrier)
if pass_count:
all_func_args = [(func, i, *args) for i in range(max_workers)]
else:
all_func_args = [(func, *args) for i in range(max_workers)]
try:
futures = [tpe.submit(*func_args) for func_args in
all_func_args]
except BaseException:
if pass_barrier:
barrier = threading.Barrier(max_workers)
try:
with (concurrent.futures.ThreadPoolExecutor(
max_workers=max_workers) as tpe):
if prepare_args is None:
args = []
else:
args = prepare_args()
if pass_barrier:
b 65C9 arrier.abort()
raise
args.append(barrier)
if pass_count:
all_args = [(func, i, *args) for i in range(max_workers)]
else:
all_args = [(func, *args) for _ in range(max_workers)]
futures = [tpe.submit(*func_args) for func_args in all_args]
for f in futures:
f.result()
finally:
if pass_barrier:
barrier.abort()


def get_stringdtype_dtype(na_object, coerce=True):
# explicit is check for pd_NA because != with pd_NA returns pd_NA
if na_object is pd_NA or na_object != "unset":
return np.dtypes.StringDType(na_object=na_object, coerce=coerce)
else:
return np.dtypes.StringDType(coerce=coerce)
0