From 02df6ee1a61666019d9d6b745960b2605e43f4c8 Mon Sep 17 00:00:00 2001 From: Eivind Jahren Date: Thu, 23 Jan 2025 14:52:31 +0100 Subject: [PATCH] Remove unused async_utils.py --- src/_ert/async_utils.py | 54 ----------------------------------------- 1 file changed, 54 deletions(-) delete mode 100644 src/_ert/async_utils.py diff --git a/src/_ert/async_utils.py b/src/_ert/async_utils.py deleted file mode 100644 index efd49b958b8..00000000000 --- a/src/_ert/async_utils.py +++ /dev/null @@ -1,54 +0,0 @@ -from __future__ import annotations - -import asyncio -import logging -import traceback -from collections.abc import Coroutine, Generator -from contextlib import suppress -from typing import Any, TypeVar - -logger = logging.getLogger(__name__) - -_T = TypeVar("_T") -_T_co = TypeVar("_T_co", covariant=True) - - -def new_event_loop() -> asyncio.AbstractEventLoop: - loop = asyncio.new_event_loop() - loop.set_task_factory(_create_task) - return loop - - -def get_running_loop() -> asyncio.AbstractEventLoop: - try: - return asyncio.get_running_loop() - except RuntimeError: - loop = new_event_loop() - asyncio.set_event_loop(loop) - return loop - - -def _create_task( - loop: asyncio.AbstractEventLoop, - coro: Coroutine[Any, Any, _T] | Generator[Any, None, _T], -) -> asyncio.Task[_T]: - assert asyncio.iscoroutine(coro) - task = asyncio.Task(coro, loop=loop) - task.add_done_callback(_done_callback) - return task - - -def _done_callback(task: asyncio.Task[_T_co]) -> None: - assert task.done() - with suppress(asyncio.CancelledError): - if (exc := task.exception()) is None: - return - - exc_traceback = "".join( - traceback.format_exception(None, exc, exc.__traceback__) - ) - logger.error( - f"Exception in scheduler task {task.get_name()}: {exc}\n" - f"Traceback: {exc_traceback}" - ) - raise exc