Kill a process tree (including grandchildren) with signal "sig" and return a (gone, still_alive) tuple. "on_terminate", if specified, is a callabck function which is called as soon as a child terminates.
(pid, sig=signal.SIGTERM, include_parent=True,
timeout=None, on_terminate=None)
| 19 | """ |
| 20 | |
| 21 | def kill_proc_tree(pid, sig=signal.SIGTERM, include_parent=True, |
| 22 | timeout=None, on_terminate=None): |
| 23 | """Kill a process tree (including grandchildren) with signal |
| 24 | "sig" and return a (gone, still_alive) tuple. |
| 25 | "on_terminate", if specified, is a callabck function which is |
| 26 | called as soon as a child terminates. |
| 27 | """ |
| 28 | if pid == os.getpid(): |
| 29 | raise RuntimeError("I refuse to kill myself") |
| 30 | parent = psutil.Process(pid) |
| 31 | children = parent.children(recursive=True) |
| 32 | if include_parent: |
| 33 | children.append(parent) |
| 34 | for p in children: |
| 35 | p.send_signal(sig) |
| 36 | gone, alive = psutil.wait_procs(children, timeout=timeout, |
| 37 | callback=on_terminate) |
| 38 | return (gone, alive) |
| 39 | |
| 40 | |
| 41 | def show_list_by_name(window): |