| 465 | |
| 466 | |
| 467 | async def clear_stream_queue(): |
| 468 | import queue |
| 469 | |
| 470 | from api_utils.server_state import state |
| 471 | |
| 472 | STREAM_QUEUE = state.STREAM_QUEUE |
| 473 | logger = state.logger |
| 474 | |
| 475 | if STREAM_QUEUE is None: |
| 476 | return |
| 477 | cleared_count = 0 |
| 478 | while True: |
| 479 | try: |
| 480 | await asyncio.to_thread(STREAM_QUEUE.get_nowait) |
| 481 | cleared_count += 1 |
| 482 | except queue.Empty: |
| 483 | break |
| 484 | except Exception: |
| 485 | break |
| 486 | if cleared_count > 0: |
| 487 | logger.info(f"Stream queue cleared. Items: {cleared_count}") |
| 488 | |
| 489 | |
| 490 | async def detect_function_calls_from_dom( |