Skip to content

Commit

Permalink
CLI: Add --all flag to verdi process kill (#6075)
Browse files Browse the repository at this point in the history
  • Loading branch information
chrisjsewell committed Jul 7, 2023
1 parent 923cc31 commit db13759
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 2 deletions.
11 changes: 9 additions & 2 deletions aiida/cmdline/commands/cmd_process.py
Expand Up @@ -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 <PID>`.')

Expand Down
11 changes: 11 additions & 0 deletions tests/cmdline/commands/test_process.py
Expand Up @@ -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`'

0 comments on commit db13759

Please sign in to comment.