Skip to content

Commit

Permalink
fix: first concurrency issue in Python 3.13t (#1310)
Browse files Browse the repository at this point in the history
  • Loading branch information
jpivarski authored Oct 7, 2024
1 parent 7ed26a2 commit a8f674e
Showing 1 changed file with 15 additions and 6 deletions.
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

0 comments on commit a8f674e

Please sign in to comment.