Safely set result on future, handling race conditions.
()
| 255 | if not future.done(): |
| 256 | |
| 257 | def safe_set_result(): |
| 258 | """Safely set result on future, handling race conditions.""" |
| 259 | try: |
| 260 | if not future.done(): |
| 261 | if response.error is None: |
| 262 | future.set_result(response.result) |
| 263 | else: |
| 264 | future.set_exception(response.error) |
| 265 | except asyncio.InvalidStateError: |
| 266 | # Future was cancelled or completed between the check and set |
| 267 | # This is expected in high-load scenarios, just log and continue |
| 268 | if enable_llmapi_debug() or logger.level == 'debug': |
| 269 | logger_debug( |
| 270 | f"[client] Future already done for request_id: {response.request_id}, skipping" |
| 271 | ) |
| 272 | |
| 273 | if enable_llmapi_debug() or logger.level == 'debug': |
| 274 | if response.error is None: |
nothing calls this directly
no test coverage detected