Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
API: Add function to start the daemon (#5625)
So far, the daemon could only be started through `verdi` and there was no way to do it from the Python API. Here we add the `start_daemon` method to the `aiida.engine.daemon.client.DaemonClient` class which will start the daemon when called. To start the daemon, the function will actually still invoke the `verdi` command through a subprocess. The reason is that starting the daemon will put the calling process in the background, which is not the desired behavior when calling it from the API. The actual code that launches the circus daemon is moved from the `verdi` command to the `_start_daemon` method of the `DaemonClient`. In this way, the daemon functionality is more self-contained. By making it a protected method, we signal that users of the Python API should probably not use it, but use the public `start_daemon` instead. This implementation may seem to have some circularity, as `start_daemon` will call a `verdi` command, which in turn will call the `_start_daemon` method of the `DaemonClient`. The reason for this is that the `verdi` command ensures that the correct profile is loaded before starting the daemon. We could make a separate CLI end point independent of `verdi` that just serves to load a profile and start the daemon, but that seems unnecessarily complicated at this point. Besides the added function, which was the main goal, the code is also refactored considerably. The implementation of the command line command `verdi daemon start-circus` is now moved to the `_start_circus` method of the `DaemonClient` class. The `verdi devel run_daemon` command is moved to `verdi daemon worker`, which makes more sense as a location. This command launches a single daemon worker, which is nothing more than an AiiDA process that runs a `Runner` instance in blocking mode. The `verdi daemon start` will run a circus daemon that manages instances of these daemon workers. To better match the nomenclature, the module `aiida.engine.daemon.runner` was renamed to `worker`.
- Loading branch information