Skip to content

Commit

Permalink
avoid sequentially process the retried entries. do parallel async
Browse files Browse the repository at this point in the history
  • Loading branch information
CharlieJCJ committed Dec 4, 2024
1 parent 232dab5 commit 50ee9e7
Showing 1 changed file with 8 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -329,6 +329,7 @@ async def process_requests_from_file(
await asyncio.gather(*pending_requests)

# Process any remaining retries in the queue
pending_retries = []
while not queue_of_requests_to_retry.empty():
retry_request = await queue_of_requests_to_retry.get()
token_estimate = self.estimate_total_tokens(retry_request.generic_request.messages)
Expand Down Expand Up @@ -356,7 +357,12 @@ async def process_requests_from_file(
status_tracker=status_tracker,
)
)
await task
pending_retries.append(task)
await asyncio.sleep(0.1) # Allow other tasks to run

# Wait for all retry tasks to complete
if pending_retries:
await asyncio.gather(*pending_retries)

status_tracker.pbar.close()

Expand Down Expand Up @@ -406,7 +412,7 @@ async def handle_single_request_with_retries(

except Exception as e:
logger.warning(
f"Request {request.task_id} failed with Exception {e}, attempts left {request.attempts_left-1}"
f"Request {request.task_id} failed with Exception {e}, attempts left {request.attempts_left}"
)
status_tracker.num_other_errors += 1
request.result.append(e)
Expand Down

0 comments on commit 50ee9e7

Please sign in to comment.