Daemon#

AiiDA provides a daemon process that runs in the background which handles any new processes (i.e., calculations and workflows, see process concepts) that are submitted. Unlike when running a process, which blocks the current Python interpreter (see the launching section for details on the difference between run and submit), the daemon can handle multiple processes asynchronously.

The daemon concept in AiiDA consists of multiple system processes.

Note

System processes, here, refers to processes that are run by the operating system, not to the AiiDA specific collective term for all calculations and workflows.

When the daemon is started, a single system process is launched in the background that runs indefinitely until it is stopped. This daemonized process is responsible for launching and then monitoring one or multiple daemon workers. Each daemon worker is another system process that connects to RabbitMQ to retrieve calculations and workflows that have been submitted and run them to completion. If a daemon worker dies, the daemon will automatically revive it. When the daemon is requested to stop, it will send a signal to all workers to shut them down before shutting down itself.

In summary: AiiDA’s daemon consists of a single system process running in the background (the daemon) that manages one or more system processes that handle all submitted calculations and workflows (the daemon workers).

Client#

The Python API provides the DaemonClient class to interact with the daemon. It can either be constructed directly for a given profile, or the aiida.engine.get_daemon_client() utility function can be used to construct it. In order to control the daemon for the current default profile:

from aiida.engine import get_daemon_client
client = get_daemon_client()

It is also possible to explicitly specify a profile:

client = get_daemon_client(profile='some-profile')

The daemon can be started and stopped through the client:

client.start_daemon()
assert client.is_daemon_running
client.stop_daemon(wait=True)

The main methods of interest for interacting with the daemon are:

These methods will raise a DaemonException if the daemon fails to start or calls to it fail. All methods accept a timeout argument, which is the number of seconds the client should wait for the daemon process to respond, before raising a DaemonTimeoutException. The default for the timeout is taken from the daemon.timeout configuration option and is set when constructing the DaemonClient.

Note

The DaemonClient only directly interacts with the main daemon process, not with any of the daemon workers that it manages.