From 1bd4fe1294258050dd495e9a33ba3d23f47149b7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C3=98yvind=20Eide?= Date: Thu, 19 Dec 2024 15:50:19 +0100 Subject: [PATCH] Remove unused async_run --- src/everest/util/__init__.py | 1 - src/everest/util/async_run.py | 37 ----------------------------- tests/everest/test_async_run.py | 41 --------------------------------- 3 files changed, 79 deletions(-) delete mode 100644 src/everest/util/async_run.py delete mode 100644 tests/everest/test_async_run.py diff --git a/src/everest/util/__init__.py b/src/everest/util/__init__.py index f6366d1754d..43fb27cb5ee 100644 --- a/src/everest/util/__init__.py +++ b/src/everest/util/__init__.py @@ -7,7 +7,6 @@ from ert.shared.version import version as ert_version from everest.plugins.everest_plugin_manager import EverestPluginManager from everest.strings import DATE_FORMAT, EVEREST -from everest.util.async_run import async_run # noqa try: import opm.io diff --git a/src/everest/util/async_run.py b/src/everest/util/async_run.py deleted file mode 100644 index 3a308497469..00000000000 --- a/src/everest/util/async_run.py +++ /dev/null @@ -1,37 +0,0 @@ -from threading import Thread - - -def async_run(function, on_finished=None, on_error=None): - """Run a function in a separate thread. - - If the function raise an exception, on_error is called, with the - exception as first argument. - When the excecution is finished (either successfully or with an - exception), on_finished is called with: - - first argument is the value returned by the function - - second argument is None if the function completed correctly, or - it is the exception that stopeed the excecution - """ - runner = _AsyncRunner(function, on_finished, on_error) - runner.start() - - -class _AsyncRunner(Thread): - def __init__(self, function=None, on_finished=None, on_error=None): - super().__init__() - self._function = function - self._on_finished = on_finished - self._on_error = on_error - - def run(self): - ret = None - error = None - try: - ret = self._function() - except Exception as e: - error = e - if self._on_error is not None: - self._on_error(e) - finally: - if self._on_finished is not None: - self._on_finished(ret, error) diff --git a/tests/everest/test_async_run.py b/tests/everest/test_async_run.py deleted file mode 100644 index 307e6543ef8..00000000000 --- a/tests/everest/test_async_run.py +++ /dev/null @@ -1,41 +0,0 @@ -from functools import partial -from time import sleep - -from everest.util import async_run - - -def workflow_good(): - sleep(0.1) - - -def workflow_bad(): - sleep(0.1) - raise RuntimeError("I am a failure") - - -def _on_runner_error(error, expected_error): - # Compare repr since we can't compare RuntimeErrors directly - assert repr(error) == repr(expected_error) - - -def _on_runner_finished(_, error, expected_error): - # Compare repr since we can't compare RuntimeErrors directly - assert repr(error) == repr(expected_error) - - -def test_async_run(): - # test successful run - expected_error = None - async_run( - workflow_good, - on_error=partial(_on_runner_error, expected_error=expected_error), - on_finished=partial(_on_runner_finished, expected_error=expected_error), - ) - - # test failing run - expected_error = RuntimeError("I am a failure") - async_run( - workflow_bad, - on_error=partial(_on_runner_error, expected_error=expected_error), - on_finished=partial(_on_runner_finished, expected_error=expected_error), - )