|
8 | 8 | ########################################################################### |
9 | 9 | """Plugin for direct execution.""" |
10 | 10 |
|
| 11 | +from typing import Union |
| 12 | + |
11 | 13 | import aiida.schedulers |
12 | 14 | from aiida.common.escaping import escape_for_bash |
13 | 15 | from aiida.schedulers import SchedulerError |
@@ -354,13 +356,28 @@ def _parse_submit_output(self, retval, stdout, stderr): |
354 | 356 |
|
355 | 357 | return stdout.strip() |
356 | 358 |
|
357 | | - def _get_kill_command(self, jobid): |
358 | | - """Return the command to kill the job with specified jobid.""" |
359 | | - submit_command = f'kill {jobid}' |
| 359 | + def _get_kill_command(self, jobid: Union[int, str]) -> str: |
| 360 | + """Return the command to kill the process with specified id and all its descendants. |
| 361 | +
|
| 362 | + :param jobid: The job id is in the case of the |
| 363 | + :py:class:`~aiida.schedulers.plugins.direct.DirectScheduler` the process id. |
| 364 | +
|
| 365 | + :return: A string containing the kill command. |
| 366 | + """ |
| 367 | + from psutil import Process |
| 368 | + |
| 369 | + # get a list of the process id of all descendants |
| 370 | + process = Process(int(jobid)) |
| 371 | + children = process.children(recursive=True) |
| 372 | + jobids = [str(jobid)] |
| 373 | + jobids.extend([str(child.pid) for child in children]) |
| 374 | + jobids_str = ' '.join(jobids) |
| 375 | + |
| 376 | + kill_command = f'kill {jobids_str}' |
360 | 377 |
|
361 | 378 | self.logger.info(f'killing job {jobid}') |
362 | 379 |
|
363 | | - return submit_command |
| 380 | + return kill_command |
364 | 381 |
|
365 | 382 | def _parse_kill_output(self, retval, stdout, stderr): |
366 | 383 | """Parse the output of the kill command. |
|
0 commit comments