Skip to content

Commit

Permalink
ENH: Log progress when asking multiple questions
Browse files Browse the repository at this point in the history
skipci
  • Loading branch information
cortadocodes committed Oct 2, 2023
1 parent 953c50f commit 1c1dc91
Showing 1 changed file with 3 additions and 1 deletion.
4 changes: 3 additions & 1 deletion octue/resources/child.py
Original file line number Diff line number Diff line change
Expand Up @@ -123,13 +123,15 @@ def 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)
}

for future in concurrent.futures.as_completed(future_to_question_index_mapping):
for i, future in enumerate(concurrent.futures.as_completed(future_to_question_index_mapping)):
logger.info("%d of %d answers received.", i + 1, len(questions))
question_index = future_to_question_index_mapping[future]

try:
Expand Down

0 comments on commit 1c1dc91

Please sign in to comment.