From d6e4fbb57536b5bd3192c7da529325c75919ba7b Mon Sep 17 00:00:00 2001 From: napocornejo Date: Mon, 21 Oct 2024 11:04:29 +0200 Subject: [PATCH] [QI2-1119] implemented more compact code --- qiskit_quantuminspire/utils.py | 11 +++-------- 1 file changed, 3 insertions(+), 8 deletions(-) diff --git a/qiskit_quantuminspire/utils.py b/qiskit_quantuminspire/utils.py index 330c94f..bc08447 100644 --- a/qiskit_quantuminspire/utils.py +++ b/qiskit_quantuminspire/utils.py @@ -18,13 +18,8 @@ def is_coupling_map_complete(coupling_map: CouplingMap) -> bool: def run_async(async_function: Coroutine[Any, Any, Any]) -> Any: try: - loop = asyncio.get_running_loop() - except RuntimeError: # 'RuntimeError: There is no current event loop...' - loop = None - - if loop and loop.is_running(): + _ = asyncio.get_running_loop() with concurrent.futures.ThreadPoolExecutor() as executor: - future = executor.submit(asyncio.run, async_function) - return future.result() - else: + return executor.submit(asyncio.run, async_function).result() + except RuntimeError: return asyncio.run(async_function)