Skip to content

Commit

Permalink
Start runner in a dedicated thread
Browse files Browse the repository at this point in the history
  • Loading branch information
unkcpz committed Dec 28, 2024
1 parent 01f92f7 commit 69db549
Showing 1 changed file with 7 additions and 2 deletions.
9 changes: 7 additions & 2 deletions src/aiida/engine/daemon/worker.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
import logging
import signal
import sys
import threading

from aiida.common.log import configure_logging
from aiida.engine.daemon.client import get_daemon_client
Expand Down Expand Up @@ -98,9 +99,13 @@ def start_daemon_worker(foreground: bool = False) -> None:
# https://github.com/python/mypy/issues/12557
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.
LOGGER.info('Starting a daemon worker')
runner_thread = threading.Thread(target=runner.start, daemon=True)
runner_thread.start()

try:
LOGGER.info('Starting a daemon worker')
runner.start()
runner_thread.join()
except SystemError as exception:
LOGGER.info('Received a SystemError: %s', exception)
runner.close()
Expand Down

0 comments on commit 69db549

Please sign in to comment.