Fix kill_proc_tree recipe: kill children bottom-up and add os.killpg note#2785
Open
r266-tech wants to merge 1 commit into
Open
Fix kill_proc_tree recipe: kill children bottom-up and add os.killpg note#2785r266-tech wants to merge 1 commit into
r266-tech wants to merge 1 commit into
Conversation
…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)
giampaolo
reviewed
Mar 22, 2026
| 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. |
Owner
There was a problem hiding this comment.
Can you please not make this a ..note:? It "shows up" too much. Other than that it's fine.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Changes
Two doc improvements to the
kill_proc_treerecipe indocs/recipes.rst:1. Kill children bottom-up (fixes #2573)
Added
children.reverse()before killing. Thechildren(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()withprocess_group=0is 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