Document that process_iter() also swallows ZombieProcess during pre-fetch - #2996
Open
afonsojanu wants to merge 1 commit into
Open
afonsojanu wants to merge 1 commit into
afonsojanu wants to merge 1 commit into
Conversation
process_iter()'s docstring only mentioned AccessDenied as the exception that gets turned into ad_value during attrs pre-fetch, but as_dict() (which it calls internally) has always caught ZombieProcess the same way. On Linux this shows up for real when a process becomes a zombie between listing PIDs and fetching an attr like num_fds() (see giampaolo#2831), and the silent None can catch people off guard if they only expected AccessDenied to behave this way. Added a regression test next to the existing AccessDenied one to lock in the same behavior for ZombieProcess.
This branch has not been deployed
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.
While digging into #2831, I noticed
process_iter()'s docstring only mentionsAccessDeniedas the exception that gets turned intoad_valuewhen an attr fails during pre-fetch. But it delegates toas_dict()internally, andas_dict()has always caughtZombieProcessthe same way (see the existing test for it at line ~1240 in test_process.py).On Linux this is exactly what's happening in #2831:
num_fds()raisesZombieProcesswhen a process exits between listing PIDs and reading/proc/pid/fd(traced throughwrap_exceptions()->_raise_if_zombie()), soprocess_iter(attrs=['num_fds'])silently returnsNonefor that process instead of raising anything the caller could catch around the access. That's arguably fine behavior, matching what already happens for AccessDenied, but the docstring not mentioning it is what threw the reporter off.Small change:
process_iter()docstring in bothpsutil/__init__.pyanddocs/api.rstto mentionZombieProcessalongsideAccessDeniedtests/test_system.pyright next to the existing AccessDenied one, mocking the platform-specific method the same way the AccessDenied test does, to lock in thatprocess_iter()'s own pre-fetch path behaves the same asas_dict()'sRan the full
test_system.py,test_process.pyandtest_misc.pysuites locally (macOS), all green aside from one pre-existing, unrelatedtest_cmdlinefailure caused by how my venv's python3 resolves its own framework path, confirmed to fail identically on unmodified master.