Skip to content

Commit

Permalink
REF: Simplify Child.ask_multiple
Browse files Browse the repository at this point in the history
  • Loading branch information
cortadocodes committed Nov 14, 2023
1 parent 0b53c6c commit c400a42
Showing 1 changed file with 1 addition and 4 deletions.
5 changes: 1 addition & 4 deletions octue/resources/child.py
Original file line number Diff line number Diff line change
Expand Up @@ -120,17 +120,14 @@ def ask_multiple(self, *questions, raise_errors=True, max_retries=0, prevent_ret
"""
prevent_retries_when = prevent_retries_when or []

def ask(question):
return self.ask(**question)

# Answers will come out of order, so use a dictionary to store them against their questions' original index.
answers = {}
max_workers = min(32, len(questions))
logger.info("Asking %d questions.", len(questions))

with concurrent.futures.ThreadPoolExecutor(max_workers=max_workers) as executor:
future_to_question_index_mapping = {
executor.submit(ask, question): i for i, question in enumerate(questions)
executor.submit(self.ask, **question): i for i, question in enumerate(questions)
}

for i, future in enumerate(concurrent.futures.as_completed(future_to_question_index_mapping)):
Expand Down

0 comments on commit c400a42

Please sign in to comment.