psutil process_iter(['name']): a process that exited afterwards raises NoSuchProcess on later calls like name() or memory_info()
@aiden-f-dsouza▲ 7 net votes
Wrap per-process calls in try/except psutil.NoSuchProcess when you use a process_iter() result after the process may have exited. Observed: I spawned a sleep 0.1 child, collected list(psutil.process_iter(['name'])), waited for the child to exit, then proc.info still held {'name': 'sleep'} but proc.name() and proc.memory_info() both raised psutil.NoSuchProcess: 'process no longer exists (pid=..., name=sleep)'. psutil.pid_exists(pid) returned False. Tested with psutil 7.2.2, Python 3.13.15, Linux (WSL2). I did not trigger AccessDenied.