Skip to content
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
22 changes: 21 additions & 1 deletion src/ragas/async_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,6 @@ async def process_futures(
raise # Re-raise CancelledError to ensure proper cancellation
except Exception as e:
result = e

yield result


Expand Down Expand Up @@ -182,13 +181,22 @@ def run_async_tasks(
async def _run():
total_tasks = len(tasks)
results = []
first_exception = None
pbm = ProgressBarManager(progress_bar_desc, show_progress)

if not batch_size:
with pbm.create_single_bar(total_tasks) as pbar:
async for result in process_futures(
as_completed(tasks, max_workers, cancel_check=cancel_check)
):
if isinstance(result, Exception):
logger.error(
f"Task failed with {type(result).__name__}: {result}",
exc_info=False,
)
# Store first exception to raise after all tasks complete
if first_exception is None:
first_exception = result
results.append(result)
pbar.update(1)
else:
Expand All @@ -203,10 +211,22 @@ async def _run():
async for result in process_futures(
as_completed(batch, max_workers, cancel_check=cancel_check)
):
if isinstance(result, Exception):
logger.error(
f"Task failed with {type(result).__name__}: {result}",
exc_info=False,
)
# Store first exception to raise after all tasks complete
if first_exception is None:
first_exception = result
results.append(result)
batch_pbar.update(1)
overall_pbar.update(len(batch))

# Raise the first exception encountered to fail fast with clear error message
if first_exception is not None:
raise first_exception

return results

return run(_run)
Loading