Skip to content

Fix #2793: process_iter() skips zombie processes#2818

Open
EhteshamSid wants to merge 1 commit intogiampaolo:masterfrom
EhteshamSid:fix/process-iter-zombie
Open

Fix #2793: process_iter() skips zombie processes#2818
EhteshamSid wants to merge 1 commit intogiampaolo:masterfrom
EhteshamSid:fix/process-iter-zombie

Conversation

@EhteshamSid
Copy link
Copy Markdown

Fixes #2793.

ZombieProcess is a subclass of NoSuchProcess, so the except NoSuchProcess clause in the inner loop of process_iter() was catching it and calling remove(pid) - same as if the process had disappeared. That meant zombies were silently dropped from the iteration instead of being yielded.

The fix adds an explicit except ZombieProcess handler before except NoSuchProcess and yields the process. The if proc is not None guard covers the case where ZombieProcess is raised during add(pid) before proc is assigned (shouldn't happen in practice since Process.__init__ catches it internally, but worth being safe about).

Added test_emulate_zombie alongside the existing test_emulate_nsp / test_emulate_access_denied tests which do the same kind of mock-based check.

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.

process_iter() skips zombie processes

1 participant