Unverified Commit 70769902 authored by Biswa Panda's avatar Biswa Panda Committed by GitHub
Browse files

fix: prevent crash looping hello world (#2625)

parent 9ab37d94
...@@ -31,10 +31,33 @@ async def worker(runtime: DistributedRuntime): ...@@ -31,10 +31,33 @@ async def worker(runtime: DistributedRuntime):
client = await endpoint.client() client = await endpoint.client()
await client.wait_for_instances() await client.wait_for_instances()
# Issue request and process the stream idx = 0
stream = await client.generate("world,sun,moon,star") base_delay = 0.1 # Start with 100ms
async for response in stream: max_delay = 5.0 # Max 5 seconds
print(response.data()) current_delay = base_delay
while True:
try:
# Issue request and process the stream
idx += 1
stream = await client.generate(f"Query[{idx}] Hello world")
async for response in stream:
print(response.data())
# Reset backoff on successful iteration
current_delay = base_delay
# Sleep for 1 second
await asyncio.sleep(1)
except asyncio.CancelledError:
# Re-raise for graceful shutdown
raise
except Exception as e:
# Log the exception with context
print(f"Error in worker iteration {idx}: {type(e).__name__}: {e}")
# Perform exponential backoff
print(f"Retrying after {current_delay:.2f} seconds...")
await asyncio.sleep(current_delay)
# Double the delay for next time, up to max_delay
current_delay = min(current_delay * 2, max_delay)
if __name__ == "__main__": if __name__ == "__main__":
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment