summaryrefslogtreecommitdiffstats
path: root/extras/pg
diff options
context:
space:
mode:
authorOle Troan <otroan@employees.org>2024-12-06 16:49:25 +0100
committerDamjan Marion <dmarion@0xa5.net>2024-12-16 10:02:48 +0000
commit0ad98a8c9d36fe2363e9bb6a23a500c4097b25fc (patch)
treeafdd7c47208a2e31c09b609887d8188671982d46 /extras/pg
parentd8bab19b8dd3229baf0d0b87c68b3a19f2c53bfb (diff)
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 <otroan@employees.org>
Diffstat (limited to 'extras/pg')
0 files changed, 0 insertions, 0 deletions