end18 / psutil

Automatically exported from code.google.com/p/psutil
Other
0 stars 0 forks source link

An exception should be raised when retrieving info about a dead process #15

Closed GoogleCodeExporter closed 9 years ago

GoogleCodeExporter commented 9 years ago
What steps will reproduce the problem?
1. p = Process(1234)
2. time.sleep(5)  # time-consuming task, process dies in meantime
3. p.name 
Traceback (most recent call last):
  File "<stdin>", line 1, in ?
  File "psutil/psutil.py", line 69, in name
    self.deproxy()
  File "psutil/psutil.py", line 58, in deproxy
    self._procinfo = _platform_impl.get_process_info(self._procinfo.pid)
  File "psutil/_pslinux.py", line 39, in get_process_info
    f = open("/proc/%s/stat" %pid)
IOError: [Errno 2] No such file or directory: '/proc/1234/stat'

As discussed in Issue 12 it would make sense that NoSuchProcess is raised
when we attempt to retrieve info from a Process() instance referring to a
process which is dead in meantime.

Issue 12 includes a patch which solves this issue on Linux but before doing
anything we should figure out how to implement that same thing on Windows
and OS X in a reliable way as well.

As pointed out by Jay it seems acceptable that we check for process
"aliveness" only when calling get_process_info() and avoid to raise
NoSuchProcess in case the process dies later.

Original issue reported on code.google.com by billiej...@gmail.com on 18 Feb 2009 at 6:25

GoogleCodeExporter commented 9 years ago
Fixed on Linux as r135.

Original comment by billiej...@gmail.com on 20 Feb 2009 at 12:42

GoogleCodeExporter commented 9 years ago
This is as fixed as it's going to get for now on OS X and Windows... We're just
checking if the PID exists right before executing the code to retrieve process
information. Ideally we would have some more definitive way to determine if the
process dies in mid-data collection but realistically dealing with process 
lists is
always going to be a race condition where the process can randomly disappear at 
any
moment. 

For now we raise an exception in the majority of cases, but theoretically it is
probably possible that we might end up returning invalid values (e.g. None), 
should
the process go away while get_process_info() is still executing.

Original comment by jlo...@gmail.com on 20 Feb 2009 at 4:33

GoogleCodeExporter commented 9 years ago

Original comment by billiej...@gmail.com on 20 Feb 2009 at 10:12

GoogleCodeExporter commented 9 years ago
get_process_info() should raise an exception if any part of data collection 
fails on
both Windows and OS X. If Linux platform is completed we can close this out. 

Original comment by jlo...@gmail.com on 21 Feb 2009 at 2:04

GoogleCodeExporter commented 9 years ago

Original comment by billiej...@gmail.com on 23 Feb 2009 at 5:49

GoogleCodeExporter commented 9 years ago
The test case for this issue has been added a while ago and it's reasonably 
reliable,
so if you haven't reported any failure for OS X I guess everything should be 
fine.
Closing this out as Verified.

Original comment by billiej...@gmail.com on 24 Feb 2009 at 3:27

GoogleCodeExporter commented 9 years ago

Original comment by billiej...@gmail.com on 17 Mar 2009 at 3:31

GoogleCodeExporter commented 9 years ago
Updated csets after the SVN -> Mercurial migration:
r135 == revision 5f1c9bf2dbe4

Original comment by g.rodola on 2 Mar 2013 at 11:42