Spaces:
Running
Running
Pulastya B commited on
Commit ·
e2e1cea
1
Parent(s): 132976b
FIX SSE FINALLY: Use queue.empty() check instead of catching non-existent asyncio.QueueEmpty
Browse files- src/api/app.py +3 -4
src/api/app.py
CHANGED
|
@@ -222,8 +222,7 @@ async def stream_progress(session_id: str):
|
|
| 222 |
|
| 223 |
# Stream new events from the queue (poll with get_nowait to avoid blocking issues)
|
| 224 |
while True:
|
| 225 |
-
|
| 226 |
-
# Try to get event without blocking
|
| 227 |
event = queue.get_nowait()
|
| 228 |
print(f"[SSE] GOT event from queue: {event.get('type')}")
|
| 229 |
yield f"data: {json.dumps(event)}\n\n"
|
|
@@ -231,10 +230,10 @@ async def stream_progress(session_id: str):
|
|
| 231 |
# Check if analysis is complete
|
| 232 |
if event.get('type') == 'analysis_complete':
|
| 233 |
break
|
| 234 |
-
|
| 235 |
# No events available, send keepalive and wait
|
| 236 |
yield f": keepalive\n\n"
|
| 237 |
-
await asyncio.sleep(0.
|
| 238 |
|
| 239 |
except asyncio.CancelledError:
|
| 240 |
logger.info(f"SSE stream cancelled for session {session_id}")
|
|
|
|
| 222 |
|
| 223 |
# Stream new events from the queue (poll with get_nowait to avoid blocking issues)
|
| 224 |
while True:
|
| 225 |
+
if not queue.empty():
|
|
|
|
| 226 |
event = queue.get_nowait()
|
| 227 |
print(f"[SSE] GOT event from queue: {event.get('type')}")
|
| 228 |
yield f"data: {json.dumps(event)}\n\n"
|
|
|
|
| 230 |
# Check if analysis is complete
|
| 231 |
if event.get('type') == 'analysis_complete':
|
| 232 |
break
|
| 233 |
+
else:
|
| 234 |
# No events available, send keepalive and wait
|
| 235 |
yield f": keepalive\n\n"
|
| 236 |
+
await asyncio.sleep(0.5) # Poll every 500ms
|
| 237 |
|
| 238 |
except asyncio.CancelledError:
|
| 239 |
logger.info(f"SSE stream cancelled for session {session_id}")
|