Closed GoogleCodeExporter closed 8 years ago
The assumption of expecting NoSuchProcess for a zombie processes is wrong IMO.
To say one, you are able to figure out the status of a zombie process at any
time *exactly because it is not gone yet* and as such I don't see why it should
be treated differently than any other process.
That happens not because psutil relies on /proc. Even if you'll call
p.get_cpu_affinity() or p.get_ionice() you won't get NSP and those calls derive
from actual kernel (C) function calls, they don't read a file in /proc.
Last but not least, even if checking process status for every call were the
right thing to do (and I believe it is not) we would introduce a big slowdown
just to avoid an incorrect "null" 0.0 value and that's not a good deal IMO.
Original comment by g.rodola
on 23 Jan 2014 at 6:26
I agree, it could get expensive fast; I didn't test all the different methods
on Process to see if any do raise NSP.
I was basing the assumption that it *should* raise an exception from the docs
for NoSuchProcess which read "Raised when no process with the given PID is
found in the current process list or when a process no longer exists (zombie)."
Of course "process no longer exists" and "process is a zombie" are two very
different things, so this wording is a bit confusing anyways. So if nothing
else maybe a documentation fix is in order?
And that being the case, what *would* be the recommended approach to checking
the process status in, say, a monitor loop? Just check the status once, before
making other Process method calls?
Original comment by erik.m.b...@gmail.com
on 23 Jan 2014 at 6:33
Ah! Yes I agree the wording is incorrect and should be fixed (sorry).
As for your second question: I would recommend checking process status before
anything else as in:
for p in psutil.process_iter():
try:
status = p.status
if status != psutil.STATUS_ZOMBIE:
...
except psutil.NoSuchProcess:
pass
Original comment by g.rodola
on 23 Jan 2014 at 6:46
Okay, great--that's what I think we'll end up doing in psrecord, where this
came up: https://github.com/astrofrog/psrecord/pull/7
It was just odd that this wasn't noticed until I tried running it on Linux.
But if that wasn't the expected behavior to begin with that's fine by me so
long as the docs are cleared up :)
Original comment by erik.m.b...@gmail.com
on 23 Jan 2014 at 7:39
This is now fixed in the new upcoming doc:
http://psutil.readthedocs.org/en/latest/#psutil.NoSuchProcess
Closing this out.
Original comment by g.rodola
on 1 Feb 2014 at 6:32
Original issue reported on code.google.com by
erik.m.b...@gmail.com
on 23 Jan 2014 at 5:16