Skip to content

Commit

Permalink
Revert start runner in thread since the close operation not well handled
Browse files Browse the repository at this point in the history
  • Loading branch information
unkcpz committed Dec 29, 2024
1 parent 5746ae8 commit d62816e
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 4 deletions.
11 changes: 8 additions & 3 deletions src/aiida/engine/daemon/worker.py
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down
2 changes: 1 addition & 1 deletion tests/cmdline/commands/test_rabbitmq.py
Original file line number Diff line number Diff line change
Expand Up @@ -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')
Expand Down

0 comments on commit d62816e

Please sign in to comment.