zhengzheng / psutil

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

Process getcwd() on Windows erroneously raise NoSuchProcess exceptions #252

Closed GoogleCodeExporter closed 9 years ago

GoogleCodeExporter commented 9 years ago
for p in psutil.process_iter():
    print p,
    try:
        p.getcwd()
    except psutil.AccessDenied:
        print
    except psutil.NoSuchProcess:
        print "NSP"
    else:
        print

The code above on my Windows box prints:

psutil.Process(pid=0, name='System Idle Process')
psutil.Process(pid=4, name='System')
psutil.Process(pid=268, name='smss.exe')
psutil.Process(pid=348, name='csrss.exe')
psutil.Process(pid=396, name='csrss.exe')
psutil.Process(pid=404, name='wininit.exe')
psutil.Process(pid=444, name='winlogon.exe')
psutil.Process(pid=492, name='services.exe')
psutil.Process(pid=500, name='lsass.exe')
psutil.Process(pid=508, name='lsm.exe')
psutil.Process(pid=612, name='svchost.exe')
psutil.Process(pid=668, name='VBoxService.exe')
psutil.Process(pid=696, name='svchost.exe')
psutil.Process(pid=752, name='svchost.exe')
psutil.Process(pid=852, name='svchost.exe')
psutil.Process(pid=904, name='svchost.exe')
psutil.Process(pid=988, name='svchost.exe')
psutil.Process(pid=360, name='svchost.exe')
psutil.Process(pid=300, name='svchost.exe')
psutil.Process(pid=1200, name='tlntsvr.exe')
psutil.Process(pid=1236, name='svchost.exe')
psutil.Process(pid=1560, name='svchost.exe')
psutil.Process(pid=1816, name='taskhost.exe') NSP
psutil.Process(pid=1876, name='dwm.exe') NSP
psutil.Process(pid=1912, name='explorer.exe') NSP
psutil.Process(pid=2024, name='VBoxTray.exe') NSP
psutil.Process(pid=2032, name='TortoiseHgOverlayServer.exe') NSP
psutil.Process(pid=932, name='TSVNCache.exe') NSP
psutil.Process(pid=1748, name='cmd.exe') NSP
psutil.Process(pid=1800, name='conhost.exe') NSP
psutil.Process(pid=1476, name='wmpnetwk.exe')
psutil.Process(pid=456, name='PyScripter.exe')
psutil.Process(pid=2684, name='procexp.exe')
psutil.Process(pid=188, name='procexp64.exe') NSP
psutil.Process(pid=1980, name='chrome.exe')
psutil.Process(pid=184, name='chrome.exe')
psutil.Process(pid=1768, name='python.exe')

We get different NoSuchProcess exceptions but that's not actually correct as 
processes are not really gone.
This happens because we treat ERROR_PARTIAL_COPY as an alias for "process is 
gone":
http://code.google.com/p/psutil/source/browse/tags/release-0.4.1/psutil/_psutil_
mswindows.c#650
http://code.google.com/p/psutil/source/browse/tags/release-0.4.1/psutil/_psutil_
mswindows.c#673
http://code.google.com/p/psutil/source/browse/tags/release-0.4.1/psutil/_psutil_
mswindows.c#692

That's a bad assumption. The right thing to do there is raising AccessDenied 
instead, because we simply have no way to determine process cwd.

Original issue reported on code.google.com by g.rodola on 31 Jan 2012 at 6:13

GoogleCodeExporter commented 9 years ago
Fixed in r1257.

Original comment by g.rodola on 31 Jan 2012 at 6:19

GoogleCodeExporter commented 9 years ago
0.5.0 is finally out. Closing out as fixed.

Original comment by g.rodola on 27 Jun 2012 at 6:54

GoogleCodeExporter commented 9 years ago
[deleted comment]
GoogleCodeExporter commented 9 years ago
Updated csets after the SVN -> Mercurial migration:
r1257 == revision 371e5acb4d40

Original comment by g.rodola on 2 Mar 2013 at 12:06