[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[PULL 22/32] python/aqmp: add asyncio_run compatibility wrapper
From: |
John Snow |
Subject: |
[PULL 22/32] python/aqmp: add asyncio_run compatibility wrapper |
Date: |
Mon, 27 Sep 2021 15:25:03 -0400 |
As a convenience. It isn't used by the library itself, but it is used by
the test suite. It will also come in handy for users of the library
still on Python 3.6.
Signed-off-by: John Snow <jsnow@redhat.com>
Message-id: 20210915162955.333025-23-jsnow@redhat.com
Signed-off-by: John Snow <jsnow@redhat.com>
---
python/qemu/aqmp/util.py | 19 +++++++++++++++++++
1 file changed, 19 insertions(+)
diff --git a/python/qemu/aqmp/util.py b/python/qemu/aqmp/util.py
index 52a15321889..eaa5fc7d5f9 100644
--- a/python/qemu/aqmp/util.py
+++ b/python/qemu/aqmp/util.py
@@ -147,6 +147,25 @@ async def wait_closed(writer: asyncio.StreamWriter) ->
None:
await asyncio.sleep(0)
+def asyncio_run(coro: Coroutine[Any, Any, T], *, debug: bool = False) -> T:
+ """
+ Python 3.6-compatible `asyncio.run` wrapper.
+
+ :param coro: A coroutine to execute now.
+ :return: The return value from the coroutine.
+ """
+ if sys.version_info >= (3, 7):
+ return asyncio.run(coro, debug=debug)
+
+ # Python 3.6
+ loop = asyncio.get_event_loop()
+ loop.set_debug(debug)
+ ret = loop.run_until_complete(coro)
+ loop.close()
+
+ return ret
+
+
# ----------------------------
# Section: Logging & Debugging
# ----------------------------
--
2.31.1
- [PULL 12/32] python/aqmp: add AsyncProtocol._readline() method, (continued)
- [PULL 12/32] python/aqmp: add AsyncProtocol._readline() method, John Snow, 2021/09/27
- [PULL 13/32] python/aqmp: add QMP Message format, John Snow, 2021/09/27
- [PULL 14/32] python/aqmp: add well-known QMP object models, John Snow, 2021/09/27
- [PULL 15/32] python/aqmp: add QMP event support, John Snow, 2021/09/27
- [PULL 16/32] python/pylint: disable too-many-function-args, John Snow, 2021/09/27
- [PULL 17/32] python/aqmp: add QMP protocol support, John Snow, 2021/09/27
- [PULL 18/32] python/pylint: disable no-member check, John Snow, 2021/09/27
- [PULL 19/32] python/aqmp: Add message routing to QMP protocol, John Snow, 2021/09/27
- [PULL 21/32] python/aqmp: add _raw() execution interface, John Snow, 2021/09/27
- [PULL 20/32] python/aqmp: add execute() interfaces, John Snow, 2021/09/27
- [PULL 22/32] python/aqmp: add asyncio_run compatibility wrapper,
John Snow <=
- [PULL 23/32] python/aqmp: add scary message, John Snow, 2021/09/27
- [PULL 09/32] python/aqmp: add AsyncProtocol.accept() method, John Snow, 2021/09/27
- [PULL 24/32] python: bump avocado to v90.0, John Snow, 2021/09/27
- [PULL 25/32] python/aqmp: add AsyncProtocol unit tests, John Snow, 2021/09/27
- [PULL 26/32] python/aqmp: add LineProtocol tests, John Snow, 2021/09/27
- [PULL 27/32] python/aqmp: Add Coverage.py support, John Snow, 2021/09/27
- [PULL 28/32] python: Add dependencies for AQMP TUI, John Snow, 2021/09/27
- [PULL 29/32] python/aqmp-tui: Add AQMP TUI, John Snow, 2021/09/27
- [PULL 30/32] python: Add entry point for aqmp-tui, John Snow, 2021/09/27
- [PULL 31/32] python: add optional pygments dependency, John Snow, 2021/09/27