Kill all child processes recursively for a given pid. Parameters ---------- pid : int The given parameter id.
(pid)
| 34 | |
| 35 | |
| 36 | def kill_child_processes(pid): |
| 37 | """Kill all child processes recursively for a given pid. |
| 38 | |
| 39 | Parameters |
| 40 | ---------- |
| 41 | pid : int |
| 42 | The given parameter id. |
| 43 | """ |
| 44 | # pylint: disable=import-outside-toplevel |
| 45 | import psutil |
| 46 | |
| 47 | try: |
| 48 | parent = psutil.Process(pid) |
| 49 | children = parent.children(recursive=True) |
| 50 | except psutil.NoSuchProcess: |
| 51 | return |
| 52 | |
| 53 | for process in children: |
| 54 | try: |
| 55 | process.kill() |
| 56 | except psutil.NoSuchProcess: |
| 57 | pass |
| 58 | |
| 59 | |
| 60 | class StatusKind(IntEnum): |