From db50e589b85dbcda8a734ea728cd68b54fa1c486 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Gabriel=20Mart=C3=ADn=20Bl=C3=A1zquez?= Date: Wed, 20 Dec 2023 16:01:44 +0100 Subject: [PATCH] Fix `results` didn't have same order as `futures` (#173) --- src/distilabel/utils/futures.py | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/src/distilabel/utils/futures.py b/src/distilabel/utils/futures.py index 02c1e7fbc7..d12ed0103e 100644 --- a/src/distilabel/utils/futures.py +++ b/src/distilabel/utils/futures.py @@ -34,10 +34,14 @@ def when_all_complete(futures: List[Future[T]]) -> Future[T]: completed, and it will contain the results of the `futures`. """ all_done_future = Future() - results = [] + results = [None] * len(futures) def check_all_done(future: Future) -> None: - results.extend(future.result()) + # This is done to preserve the order of the results with respect to the order + # of the futures. + index = futures.index(future) + results[index] = future.result()[0] + _, not_done = wait(futures, return_when="FIRST_COMPLETED") if len(not_done) == 0: all_done_future.set_result(results)