Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Process control: Reinstate process status for paused/killed processes #5754

Merged
merged 1 commit into from
Nov 10, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 4 additions & 2 deletions aiida/cmdline/commands/cmd_process.py
Original file line number Diff line number Diff line change
Expand Up @@ -198,7 +198,8 @@ def process_kill(processes, timeout, wait):
from aiida.engine.processes import control

try:
control.kill_processes(processes, timeout=timeout, wait=wait)
message = 'Killed through `verdi process kill`'
control.kill_processes(processes, 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 All @@ -218,7 +219,8 @@ def process_pause(processes, all_entries, timeout, wait):
raise click.BadOptionUsage('all', 'cannot specify individual processes and the `--all` flag at the same time.')

try:
control.pause_processes(processes, all_entries=all_entries, timeout=timeout, wait=wait)
message = 'Paused through `verdi process pause`'
control.pause_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
12 changes: 8 additions & 4 deletions aiida/engine/processes/control.py
Original file line number Diff line number Diff line change
Expand Up @@ -112,6 +112,7 @@ def play_processes(
def pause_processes(
processes: list[ProcessNode] | None = None,
*,
message: str = 'Paused through `aiida.engine.processes.control.pause_processes`',
all_entries: bool = False,
timeout: float = 5.0,
wait: bool = False
Expand Down Expand Up @@ -140,12 +141,13 @@ def pause_processes(
return

controller = get_manager().get_process_controller()
_perform_actions(processes, controller.pause_process, 'pause', 'pausing', 'paused', timeout, wait)
_perform_actions(processes, controller.pause_process, 'pause', 'pausing', 'paused', timeout, wait, msg=message)


def kill_processes(
processes: list[ProcessNode] | None = None,
*,
message: str = 'Killed through `aiida.engine.processes.control.kill_processes`',
all_entries: bool = False,
timeout: float = 5.0,
wait: bool = False
Expand Down Expand Up @@ -174,7 +176,7 @@ def kill_processes(
return

controller = get_manager().get_process_controller()
_perform_actions(processes, controller.kill_process, 'kill', 'killing', 'killed', timeout, wait)
_perform_actions(processes, controller.kill_process, 'kill', 'killing', 'killed', timeout, wait, msg=message)


def _perform_actions(
Expand All @@ -184,7 +186,8 @@ def _perform_actions(
present: str,
past: str,
timeout: float = None,
wait: bool = False
wait: bool = False,
**kwargs: t.Any
) -> None:
"""Perform an action on a list of processes.

Expand All @@ -195,6 +198,7 @@ def _perform_actions(
:param past: The past tense of the verb that represents the action.
:param timeout: Raise a ``ProcessTimeoutException`` if the process does not respond within this amount of seconds.
:param wait: Set to ``True`` to wait for process response, for ``False`` the action is fire-and-forget.
:param kwargs: Keyword arguments that will be passed to the method ``action``.
:raises ``ProcessTimeoutException``: If the processes do not respond within the timeout.
"""
futures = {}
Expand All @@ -206,7 +210,7 @@ def _perform_actions(
continue

try:
future = action(process.pk)
future = action(process.pk, **kwargs)
except communications.UnroutableError:
LOGGER.error(f'Process<{process.pk}> is unreachable.')
else:
Expand Down
2 changes: 1 addition & 1 deletion aiida/orm/nodes/data/code/legacy.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@

warn_deprecation(
'The `Code` class is deprecated. To create an instance, use the `aiida.orm.nodes.data.code.installed.InstalledCode`'
' or `aiida.orm.nodes.data.code.portable.PortableCode` for a "remote" or "local" code, respetively. If you are '
' or `aiida.orm.nodes.data.code.portable.PortableCode` for a "remote" or "local" code, respectively. If you are '
'using this class to compare type, e.g. in `isinstance`, use `aiida.orm.nodes.data.code.abstract.AbstractCode`.',
version=3
)
Expand Down
2 changes: 2 additions & 0 deletions tests/cmdline/commands/test_process.py
Original file line number Diff line number Diff line change
Expand Up @@ -452,6 +452,8 @@ def test_process_kill(submit_and_await, run_cli_command):

run_cli_command(cmd_process.process_pause, [str(node.pk), '--wait'])
await_condition(lambda: node.paused)
assert node.process_status == 'Paused through `verdi process pause`'

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`'
2 changes: 2 additions & 0 deletions tests/engine/processes/test_control.py
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ def test_pause_processes(submit_and_await):

control.pause_processes([node], wait=True)
assert node.paused
assert node.process_status == 'Paused through `aiida.engine.processes.control.pause_processes`'


@pytest.mark.usefixtures('started_daemon_client')
Expand Down Expand Up @@ -84,6 +85,7 @@ def test_kill_processes(submit_and_await):
control.kill_processes([node], wait=True)
assert node.is_terminated
assert node.is_killed
assert node.process_status == 'Killed through `aiida.engine.processes.control.kill_processes`'


@pytest.mark.usefixtures('started_daemon_client')
Expand Down