Skip to content

Commit

Permalink
fix: add timeout and error handling to _wait_for_unpaused
Browse files Browse the repository at this point in the history
- Add 5 minute timeout for waiting on paused run
- Handle exceptions when checking run status
- Break out of wait loop on timeout or error
  • Loading branch information
joehewett committed Jan 31, 2025
1 parent 21f4010 commit 2398927
Showing 1 changed file with 19 additions and 5 deletions.
24 changes: 19 additions & 5 deletions src/asteroid_sdk/wrappers/openai.py
Original file line number Diff line number Diff line change
Expand Up @@ -140,12 +140,26 @@ def __init__(

async def _wait_for_unpaused(self):
"""Wait until the run is no longer in paused state."""
start_time = time.time()
timeout = 300 # 5 minute timeout

while True:
run_status = get_run_sync(client=self.chat_supervision_manager.client, run_id=str(self.run_id))
if run_status and run_status.status != "paused":
break
logging.info(f"Run {self.run_id} is paused, waiting for unpaused state...")
await asyncio.sleep(1) # Wait 1 second before checking again
try:
run_status = get_run_sync(client=self.chat_supervision_manager.client, run_id=str(self.run_id))
if run_status and run_status.status != "paused":
break

# Check if we've exceeded timeout
if time.time() - start_time > timeout:
logging.error(f"Timeout waiting for run {self.run_id} to unpause")
break

logging.info(f"Run {self.run_id} is paused, waiting for unpaused state...")
await asyncio.sleep(1) # Wait 1 second before checking again

except Exception as e:
logging.error(f"Error checking run status: {e}")
break # Exit the loop on error instead of continuing indefinitely

def create(
self,
Expand Down

0 comments on commit 2398927

Please sign in to comment.