From: Michael Fritch Date: Mon, 30 Aug 2021 22:53:07 +0000 (-0600) Subject: mgr/cephadm: run coroutines in a new event loop X-Git-Tag: v17.1.0~970^2 X-Git-Url: http://git-server-git.apps.pok.os.sepia.ceph.com/?a=commitdiff_plain;h=refs%2Fpull%2F42982%2Fhead;p=ceph.git mgr/cephadm: run coroutines in a new event loop `asyncio.run` does not exist until python37 or later Signed-off-by: Michael Fritch --- 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