Skip to content

Fix kill_proc_tree recipe: kill children bottom-up and add os.killpg note#2785

Open
r266-tech wants to merge 1 commit into
giampaolo:masterfrom
r266-tech:doc-improvements
Open

Fix kill_proc_tree recipe: kill children bottom-up and add os.killpg note#2785
r266-tech wants to merge 1 commit into
giampaolo:masterfrom
r266-tech:doc-improvements

Conversation

@r266-tech
Copy link
Copy Markdown

Changes

Two doc improvements to the kill_proc_tree recipe in docs/recipes.rst:

1. Kill children bottom-up (fixes #2573)

Added children.reverse() before killing. The children(recursive=True) method returns processes in top-down order, meaning a grandchild's parent could be killed before the grandchild itself. Reversing ensures descendants are terminated before their ancestors.

2. Add os.killpg() note (fixes #2534)

Added a note explaining that on Unix, when you started the subprocess yourself, os.killpg() with process_group=0 is a simpler stdlib alternative. This note also mentions the limitation (doesn't work on Windows, only for PIDs you own as a new process group).

Closes #2573
Closes #2534

…note

- Reverse children list before killing to ensure grandchildren are
  terminated before their parents (fixes giampaolo#2573)
- Add a note about os.killpg() as a simpler stdlib alternative for
  Unix when the process was started with process_group=0 (fixes giampaolo#2534)
Comment thread docs/recipes.rst
This approach does not work on Windows (``os.killpg`` is not
available) and it only works for PIDs that you started yourself
as a new process group. For arbitrary PIDs, use the psutil
recipe above.
Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you please not make this a ..note:? It "shows up" too much. Other than that it's fine.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[OS Independent] Reverse children in doc example "Kill process tree" Kill Process Tree docs should provide hint about os.killpg

2 participants