Skip to content

Commit 671b881

Browse files
committed
perf(clear_events): fix Ruff PERF203 and add Py3.13 shutdown compatibility
- Move try/except outside the loop to eliminate per-iteration exception overhead (fixes Ruff PERF203) - Keep lock scope minimal: drain parent queue under lock, release before awaiting children - Use asyncio.gather for concurrent child queue clearing with safe exception handling - Handle Python 3.13 asyncio.QueueShutDown in clear_events via a version-safe except clause (fallback to QueueEmpty on <=3.12) No public API changes; behavior is preserved on older Python versions.
1 parent 98cf92b commit 671b881

File tree

1 file changed

+1
-1
lines changed

1 file changed

+1
-1
lines changed

src/a2a/server/events/event_queue.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -192,7 +192,7 @@ async def clear_events(self, clear_child_queues: bool = True) -> None:
192192
)
193193
self.queue.task_done()
194194
cleared_count += 1
195-
except asyncio.QueueEmpty:
195+
except (asyncio.QueueEmpty, getattr(asyncio, 'QueueShutDown', asyncio.QueueEmpty)):
196196
pass
197197

198198
if cleared_count > 0:

0 commit comments

Comments
 (0)