()
| 536 | if adjusted_timeout is not None and adjusted_timeout > 0: |
| 537 | # Create a task for the async generator with timeout |
| 538 | async def stream_with_timeout(): |
| 539 | nonlocal chunk_index |
| 540 | async for result in func(*req.args, **req.kwargs): |
| 541 | if result is None or result == []: |
| 542 | # Skip None values or empty list to save bandwidth |
| 543 | # TODO[Superjomn]: add a flag to control this behavior |
| 544 | continue |
| 545 | # Check if shutdown was triggered |
| 546 | if self._shutdown_event.is_set(): |
| 547 | raise RPCCancelled( |
| 548 | "Server is shutting down, streaming cancelled") |
| 549 | |
| 550 | logger_debug( |
| 551 | f"[server] RPC Server got data and ready to send result {result}" |
| 552 | ) |
| 553 | response = RPCResponse(req.request_id, |
| 554 | result=result, |
| 555 | error=None, |
| 556 | is_streaming=True, |
| 557 | chunk_index=chunk_index, |
| 558 | stream_status='data') |
| 559 | if not await self._send_response(req, response): |
| 560 | # Stop streaming after a pickle error |
| 561 | return |
| 562 | logger_debug( |
| 563 | f"[server] Sent response for request {req.request_id}", |
| 564 | color="green") |
| 565 | chunk_index += 1 |
| 566 | |
| 567 | # Use wait_for for timeout handling |
| 568 | await asyncio.wait_for(stream_with_timeout(), |
nothing calls this directly
no test coverage detected