Skip to content

Document that process_iter() also swallows ZombieProcess during pre-fetch - #2996

Open
afonsojanu wants to merge 1 commit into
giampaolo:masterfrom
afonsojanu:fix/process-iter-zombie-ad-value-docs
Open

afonsojanu wants to merge 1 commit into
giampaolo:masterfrom
afonsojanu:fix/process-iter-zombie-ad-value-docs

Conversation

@afonsojanu

Copy link
Copy Markdown

While digging into #2831, I noticed process_iter()'s docstring only mentions AccessDenied as the exception that gets turned into ad_value when an attr fails during pre-fetch. But it delegates to as_dict() internally, and as_dict() has always caught ZombieProcess the 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() raises ZombieProcess when a process exits between listing PIDs and reading /proc/pid/fd (traced through wrap_exceptions() -> _raise_if_zombie()), so process_iter(attrs=['num_fds']) silently returns None for 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:

  • updated the process_iter() docstring in both psutil/__init__.py and docs/api.rst to mention ZombieProcess alongside AccessDenied
  • added a regression test in tests/test_system.py right next to the existing AccessDenied one, mocking the platform-specific method the same way the AccessDenied test does, to lock in that process_iter()'s own pre-fetch path behaves the same as as_dict()'s

Ran the full test_system.py, test_process.py and test_misc.py suites locally (macOS), all green aside from one pre-existing, unrelated test_cmdline failure caused by how my venv's python3 resolves its own framework path, confirmed to fail identically on unmodified master.

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.
@github-actions github-actions Bot added the doc component : docs/ label Sep 6, 2026

This branch has not been deployed

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

Labels

doc component : docs/

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant