Skip to content

Commit 536e4a1

Browse files
Fix: fix hello world example for python 3.12 (#98)
* feat: Update to support python 3.12 - add case statement to use the asyncio.Queue.shutdown method for 3.13+ - add special handling to allow for similar semantics as asyncio.Queue.shutdown for 3.12 Tested on multiple samples in the a2a repo and some examples in this repo * Change to 3.10 and provided detailed description about event queue usage * Fix race condition in python <= 3.12 * fix merge conflict * Fix typo
1 parent 85b521d commit 536e4a1

File tree

1 file changed

+6
-1
lines changed

1 file changed

+6
-1
lines changed

src/a2a/server/events/event_consumer.py

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -95,7 +95,6 @@ async def consume_all(self) -> AsyncGenerator[Event]:
9595
logger.debug(
9696
f'Dequeued event of type: {type(event)} in consume_all.'
9797
)
98-
yield event
9998
self.queue.task_done()
10099
logger.debug(
101100
'Marked task as done in event queue in consume_all'
@@ -117,10 +116,16 @@ async def consume_all(self) -> AsyncGenerator[Event]:
117116
)
118117
)
119118

119+
# Make sure the yield is after the close events, otherwise
120+
# the caller may end up in a blocked state where this
121+
# generator isn't called again to close things out and the
122+
# other part is waiting for an event or a closed queue.
120123
if is_final_event:
121124
logger.debug('Stopping event consumption in consume_all.')
122125
await self.queue.close()
126+
yield event
123127
break
128+
yield event
124129
except TimeoutError:
125130
# continue polling until there is a final event
126131
continue

0 commit comments

Comments
 (0)