From d62816e58bb16bbe1540b1b6d09e5a834b036ddc Mon Sep 17 00:00:00 2001 From: Jusong Yu Date: Sun, 29 Dec 2024 23:59:48 +0100 Subject: [PATCH] Revert start runner in thread since the close operation not well handled --- src/aiida/engine/daemon/worker.py | 11 ++++++++--- tests/cmdline/commands/test_rabbitmq.py | 2 +- 2 files changed, 9 insertions(+), 4 deletions(-) diff --git a/src/aiida/engine/daemon/worker.py b/src/aiida/engine/daemon/worker.py index c9694d6990..ec759fce40 100644 --- a/src/aiida/engine/daemon/worker.py +++ b/src/aiida/engine/daemon/worker.py @@ -100,12 +100,17 @@ def start_daemon_worker(foreground: bool = False) -> None: runner.loop.add_signal_handler(s, lambda s=s: asyncio.create_task(shutdown_worker(runner))) # type: ignore[misc] # XXX: check the threading use is elegantly implemented: e.g. log handle, error handle, shutdown handle. + # it should work and it is better to have runner has its own event loop to handle the aiida processes only. + # however, it randomly fail some test because of resources not elegantly handled. + # The problem is the runner running in thread is not closed when thread join, the join should be the shutdown operation. + LOGGER.info('Starting a daemon worker') - runner_thread = threading.Thread(target=runner.start, daemon=True) - runner_thread.start() + # runner_thread = threading.Thread(target=runner.start, daemon=False) + # runner_thread.start() try: - runner_thread.join() + runner.start() + # runner_thread.join() except SystemError as exception: LOGGER.info('Received a SystemError: %s', exception) runner.close() diff --git a/tests/cmdline/commands/test_rabbitmq.py b/tests/cmdline/commands/test_rabbitmq.py index a60630bbbb..b0f304459d 100644 --- a/tests/cmdline/commands/test_rabbitmq.py +++ b/tests/cmdline/commands/test_rabbitmq.py @@ -69,7 +69,7 @@ def test_tasks_revive_without_daemon(run_cli_command): assert run_cli_command(cmd_rabbitmq.cmd_tasks_revive, raises=True) -@pytest.mark.usefixtures('started_daemon_client') +@pytest.mark.usefixtures('aiida_profile_clean') def test_revive(run_cli_command, monkeypatch, aiida_code_installed, submit_and_await): """Test ``tasks revive``.""" code = aiida_code_installed(default_calc_job_plugin='core.arithmetic.add', filepath_executable='/bin/bash')