Skip to content

Commit 1c32e8f

Browse files
authored
fix: prevent crash looping hello world (#2625) (#2671)
1 parent 1a5f302 commit 1c32e8f

File tree

2 files changed

+30
-6
lines changed

2 files changed

+30
-6
lines changed

examples/runtime/hello_world/client.py

Lines changed: 27 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -31,10 +31,33 @@ async def worker(runtime: DistributedRuntime):
3131
client = await endpoint.client()
3232
await client.wait_for_instances()
3333

34-
# Issue request and process the stream
35-
stream = await client.generate("world,sun,moon,star")
36-
async for response in stream:
37-
print(response.data())
34+
idx = 0
35+
base_delay = 0.1 # Start with 100ms
36+
max_delay = 5.0 # Max 5 seconds
37+
current_delay = base_delay
38+
39+
while True:
40+
try:
41+
# Issue request and process the stream
42+
idx += 1
43+
stream = await client.generate("world,sun,moon,star")
44+
async for response in stream:
45+
print(response.data())
46+
# Reset backoff on successful iteration
47+
current_delay = base_delay
48+
# Sleep for 1 second
49+
await asyncio.sleep(1)
50+
except asyncio.CancelledError:
51+
# Re-raise for graceful shutdown
52+
raise
53+
except Exception as e:
54+
# Log the exception with context
55+
print(f"Error in worker iteration {idx}: {type(e).__name__}: {e}")
56+
# Perform exponential backoff
57+
print(f"Retrying after {current_delay:.2f} seconds...")
58+
await asyncio.sleep(current_delay)
59+
# Double the delay for next time, up to max_delay
60+
current_delay = min(current_delay * 2, max_delay)
3861

3962

4063
if __name__ == "__main__":

examples/runtime/hello_world/deploy/hello_world.yaml

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ kind: DynamoGraphDeployment
66
metadata:
77
name: hello-world
88
spec:
9+
backendFramework: vllm
910
services:
1011
Frontend:
1112
livenessProbe:
@@ -60,7 +61,7 @@ spec:
6061
command:
6162
- /bin/sh
6263
- -c
63-
- 'grep "Serving endpoint" /tmp/hello_world.log'
64+
- "exit 0"
6465
initialDelaySeconds: 60
6566
periodSeconds: 60
6667
timeoutSeconds: 30
@@ -83,4 +84,4 @@ spec:
8384
- /bin/sh
8485
- -c
8586
args:
86-
- python3 hello_world.py 2>&1 | tee /tmp/hello_world.log
87+
- python3 hello_world.py

0 commit comments

Comments
 (0)