From c2fae558c363c253a0356fafceb73f5b13b5f0f3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Daniel=20P=2E=20Berrang=C3=A9?= Date: Tue, 17 May 2022 15:36:01 +0100 Subject: libvirtaio: add better docs on best practice usage pattern MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Daniel P. Berrangé --- libvirtaio.py | 23 +++++++++++++++++++++-- 1 file changed, 21 insertions(+), 2 deletions(-) diff --git a/libvirtaio.py b/libvirtaio.py index 8fa6efe..5359a3e 100644 --- a/libvirtaio.py +++ b/libvirtaio.py @@ -21,8 +21,27 @@ Register the implementation of default loop: - >>> import libvirtaio - >>> libvirtaio.virEventRegisterAsyncIOImpl() + import asyncio + import libvirtaio + + async def myapp(): + libvirtaio.virEventRegisterAsyncIOImpl() + + conn = libvirt.open("test:///default") + +For compatibility with Python < 3.7: + + loop = asyncio.new_event_loop() + asyncio.set_event_loop(loop) + + loop.run_until_complete(myapp()) + + asyncio.set_event_loop(None) + loop.close() + +If Python >= 3.7 can be required then + + asyncio.run(myapp()) .. seealso:: https://libvirt.org/html/libvirt-libvirt-event.html -- cgit v1.2.1