Skip to content
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

fix: first concurrency issue in Python 3.13t #1310

Merged
merged 2 commits into from
Oct 7, 2024
Merged
Changes from all commits
Commits
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
21 changes: 15 additions & 6 deletions src/uproot/behaviors/TBranch.py
Original file line number Diff line number Diff line change
Expand Up @@ -2959,6 +2959,9 @@ def _regularize_expressions(
return arrays, expression_context, branchid_interpretation


_basket_arrays_lock = threading.Lock()


def _ranges_or_baskets_to_arrays(
hasbranches,
ranges_or_baskets,
Expand Down Expand Up @@ -3057,7 +3060,7 @@ def basket_to_array(basket):
context = dict(branch.context)
context["forth"] = forth_context[branch.cache_key]

basket_arrays[basket.basket_num] = interpretation.basket_array(
basket_array = interpretation.basket_array(
basket.data,
basket.byte_offsets,
basket,
Expand All @@ -3067,16 +3070,21 @@ def basket_to_array(basket):
library,
interp_options,
)
if basket.num_entries != len(basket_arrays[basket.basket_num]):
if basket.num_entries != len(basket_array):
raise ValueError(
f"""basket {basket.basket_num} in tree/branch {branch.object_path} has the wrong number of entries """
f"""(expected {basket.num_entries}, obtained {len(basket_arrays[basket.basket_num])}) when interpreted as {interpretation}
f"""(expected {basket.num_entries}, obtained {len(basket_array)}) when interpreted as {interpretation}
in file {branch.file.file_path}"""
)

basket_num = basket.basket_num
basket = None

if len(basket_arrays) == branchid_num_baskets[branch.cache_key]:
with _basket_arrays_lock:
basket_arrays[basket_num] = basket_array
len_basket_arrays = len(basket_arrays)

if len_basket_arrays == branchid_num_baskets[branch.cache_key]:
arrays[branch.cache_key] = interpretation.final_array(
basket_arrays,
entry_start,
Expand All @@ -3086,8 +3094,9 @@ def basket_to_array(basket):
branch,
interp_options,
)
# no longer needed, save memory
basket_arrays.clear()
with _basket_arrays_lock:
# no longer needed, save memory
basket_arrays.clear()

except Exception:
notifications.put(sys.exc_info())
Expand Down
Loading