diff --git a/aiida/cmdline/commands/cmd_process.py b/aiida/cmdline/commands/cmd_process.py index 717f2b58b6..7c3da143ec 100644 --- a/aiida/cmdline/commands/cmd_process.py +++ b/aiida/cmdline/commands/cmd_process.py @@ -214,16 +214,23 @@ def process_status(call_link_label, max_depth, processes): @verdi_process.command('kill') @arguments.PROCESSES() +@options.ALL(help='Kill all processes if no specific processes are specified.') @options.TIMEOUT() @options.WAIT() @decorators.with_dbenv() -def process_kill(processes, timeout, wait): +def process_kill(processes, all_entries, timeout, wait): """Kill running processes.""" from aiida.engine.processes import control + if processes and all_entries: + raise click.BadOptionUsage('all', 'cannot specify individual processes and the `--all` flag at the same time.') + + if all_entries: + click.confirm('Are you sure you want to kill all processes?', abort=True) + try: message = 'Killed through `verdi process kill`' - control.kill_processes(processes, timeout=timeout, wait=wait, message=message) + control.kill_processes(processes, all_entries=all_entries, timeout=timeout, wait=wait, message=message) except control.ProcessTimeoutException as exception: echo.echo_critical(str(exception) + '\nFrom the CLI you can call `verdi devel revive `.') diff --git a/tests/cmdline/commands/test_process.py b/tests/cmdline/commands/test_process.py index dda404ff28..c0f8a79388 100644 --- a/tests/cmdline/commands/test_process.py +++ b/tests/cmdline/commands/test_process.py @@ -478,3 +478,14 @@ def test_process_kill(submit_and_await, run_cli_command): run_cli_command(cmd_process.process_kill, [str(node.pk), '--wait']) await_condition(lambda: node.is_killed) assert node.process_status == 'Killed through `verdi process kill`' + + +@pytest.mark.requires_rmq +@pytest.mark.usefixtures('started_daemon_client') +def test_process_kill_all(submit_and_await, run_cli_command): + """Test the ``verdi process kill --all`` command.""" + node = submit_and_await(WaitProcess, ProcessState.WAITING) + + run_cli_command(cmd_process.process_kill, ['--all', '--wait'], user_input='y') + await_condition(lambda: node.is_killed) + assert node.process_status == 'Killed through `verdi process kill`'