Skip to content

Commit 69db549

Browse files
committed
Start runner in a dedicated thread
1 parent 01f92f7 commit 69db549

File tree

1 file changed

+7
-2
lines changed

1 file changed

+7
-2
lines changed

src/aiida/engine/daemon/worker.py

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
import logging
1313
import signal
1414
import sys
15+
import threading
1516

1617
from aiida.common.log import configure_logging
1718
from aiida.engine.daemon.client import get_daemon_client
@@ -98,9 +99,13 @@ def start_daemon_worker(foreground: bool = False) -> None:
9899
# https://github.com/python/mypy/issues/12557
99100
runner.loop.add_signal_handler(s, lambda s=s: asyncio.create_task(shutdown_worker(runner))) # type: ignore[misc]
100101

102+
# XXX: check the threading use is elegantly implemented: e.g. log handle, error handle, shutdown handle.
103+
LOGGER.info('Starting a daemon worker')
104+
runner_thread = threading.Thread(target=runner.start, daemon=True)
105+
runner_thread.start()
106+
101107
try:
102-
LOGGER.info('Starting a daemon worker')
103-
runner.start()
108+
runner_thread.join()
104109
except SystemError as exception:
105110
LOGGER.info('Received a SystemError: %s', exception)
106111
runner.close()

0 commit comments

Comments
 (0)