summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDaniel P. Berrangé <berrange@redhat.com>2022-05-17 15:36:01 +0100
committerDaniel P. Berrangé <berrange@redhat.com>2022-06-08 16:43:52 +0100
commitc2fae558c363c253a0356fafceb73f5b13b5f0f3 (patch)
tree85842664768d0c775ce100251b578c50bde695ba
parent376a9776598f5a5d44c70c7e844f5cab7e9bae2d (diff)
downloadlibvirt-python-c2fae558c363c253a0356fafceb73f5b13b5f0f3.tar.gz
libvirtaio: add better docs on best practice usage pattern
Signed-off-by: Daniel P. Berrangé <berrange@redhat.com>
-rw-r--r--libvirtaio.py23
1 files 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