From 20d305bc75cf15fcca4767219ef0bd9dfc015b5a Mon Sep 17 00:00:00 2001 From: Michael Fritch Date: Mon, 30 Aug 2021 16:53:07 -0600 Subject: [PATCH] mgr/cephadm: run coroutines in a new event loop `asyncio.run` does not exist until python37 or later Signed-off-by: Michael Fritch --- src/pybind/mgr/cephadm/tests/fixtures.py | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/src/pybind/mgr/cephadm/tests/fixtures.py b/src/pybind/mgr/cephadm/tests/fixtures.py index 30314ed381667..aea533990f2bd 100644 --- a/src/pybind/mgr/cephadm/tests/fixtures.py +++ b/src/pybind/mgr/cephadm/tests/fixtures.py @@ -1,5 +1,6 @@ import fnmatch import asyncio +import sys from tempfile import NamedTemporaryFile from contextlib import contextmanager @@ -37,7 +38,16 @@ def match_glob(val, pat): class MockEventLoopThread: def get_result(self, coro): - asyncio.run(coro) + if sys.version_info >= (3, 7): + return asyncio.run(coro) + + loop = asyncio.new_event_loop() + asyncio.set_event_loop(loop) + try: + return loop.run_until_complete(coro) + finally: + loop.close() + asyncio.set_event_loop(None) @contextmanager -- 2.47.3