From 0ad98a8c9d36fe2363e9bb6a23a500c4097b25fc Mon Sep 17 00:00:00 2001 From: Ole Troan Date: Fri, 6 Dec 2024 16:49:25 +0100 Subject: papi: vpp_papi asyncio support An asyncio version of the VPP Python API. A API call returns a awaitable future. In comparision to the legacy API, the extra message receive thread is no needed. from vpp_papi.vpp_papi_async import VPPApiClient async def process_events(event_queue): while True: event = await event_queue.get() print(f"*** Processing event: {event}") if event is None: return async def test(): vpp = VPPApiClient() event_queue = asyncio.Queue() event_processor_task = asyncio.create_task(process_events(event_queue)) rv = await vpp.connect("foobar", event_queue) assert rv == 0 rv = await vpp.api.show_version() rv = await vpp.api.sw_interface_dump() await event_queue.put(None) # Send sentinel to stop the event processor await asyncio.gather(event_processor_task) # Wait for them to finish await vpp.disconnect() Example of sending multiple requests and gather replies asynchronously async def test_bulk(): futures = [] for i in range(n): futures.append(vpp.api.show_version()) rv = await asyncio.gather(*futures) def main(): asyncio.run(test()) Type: feature Change-Id: Ie6bcb483930216c21a45658b72e87ba4c46f43ad Signed-off-by: Ole Troan --- src/vpp-api/python/setup.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'src/vpp-api/python/setup.py') diff --git a/src/vpp-api/python/setup.py b/src/vpp-api/python/setup.py index 832b6386352..daac032520e 100644 --- a/src/vpp-api/python/setup.py +++ b/src/vpp-api/python/setup.py @@ -21,7 +21,7 @@ requirements = [] setup( name="vpp_papi", - version="2.2.0", + version="2.3.0", description="VPP Python binding", author="Ole Troan", author_email="ot@cisco.com", -- cgit