GithubHelp home page GithubHelp logo

Comments (9)

giampaolo avatar giampaolo commented on June 20, 2024

From [email protected] on March 09, 2009 18:07:07

I looked into the C code by using some debugging prints and it seems that the culprit
is OpenProcess() which doesn't return NULL, maybe because it automatically caches
handlers of processes which existed in system process table.

By running the code below the exception is thrown at the last instruction.
Since it seems we can't rely on OpenProcess() we might borrow some of the code we
used in get_process_info() to make it raise NSP when necessary.


import time, subprocess

from psutil import Process

sub = subprocess.Popen('python')
time.sleep(0.1)
p = Process(sub.pid)
p.kill()
time.sleep(0.5)
p.create_time
p.create_time
p = Process(sub.pid)

from psutil.

giampaolo avatar giampaolo commented on June 20, 2024

From [email protected] on March 12, 2009 09:47:44

It's the same problem we had before, OpenProcess() will succeed even if the process
no longer exists in many cases, you have to also check the exit code of the process.
There's already a BOOL is_running(HANDLE hProcess) function in
arch/mswindows/process_info.c that returns TRUE or FALSE if the process is actually
running. 

However, even if you call is_running() right before getting process times, it won't
necessarily help if the process dies after that but before GetProcessTimes(). We need
to know what error code is being returned if GetProcessTimes() fails because the
process has gone away (e.g. ERROR_ACCESS_DENIED, ERROR_INVALID_PARAMETER). The only
way to find out is reproduce the error without suppressing the exception the way the
test case does and get the error code from the exception raised, or use printf
debugging to print GetLastError(). We already check for ERROR_ACCESS_DENIED from
GetProcessTimes() so maybe it's returning INVALID_PARAMETER to indicate a process
handle to a dead process?

Status: Accepted

from psutil.

giampaolo avatar giampaolo commented on June 20, 2024

From [email protected] on March 12, 2009 10:01:24

Actually, this one is different. If you print the value, you'll see that
get_create_time() is actually returning a real value, there's no error. There's no
NoSuchProcess exception raised, because the function actually succeeds in getting the
process create time. I haven't checked, but since both functions are calling
GetProcessTimes() it's likely the same thing is happening in get_cpu_times() too. 

I suggest we just close this as WontFix, and remove the assertions from the test
suite. If these functions succeed on a process that has recently died, then there's
no reason IMO to force our properties to raise an exception. If the function call to
GetProcessTimes() fails, then I think it makes sense for us to raise an exception,
which are already doing.

from psutil.

giampaolo avatar giampaolo commented on June 20, 2024

From [email protected] on March 12, 2009 11:46:53

Removed tests as r246 .

Status: WontFix

from psutil.

giampaolo avatar giampaolo commented on June 20, 2024

From [email protected] on February 22, 2010 15:22:32

(related to issue 76 )
It seems that GetExitProcess() ( r512 ) can solve this problem.
Comments?

Status: ReOpened
Labels: -Milestone-0.1.2

from psutil.

giampaolo avatar giampaolo commented on June 20, 2024

From [email protected] on February 22, 2010 15:40:25

Status: WaitingForReview

from psutil.

giampaolo avatar giampaolo commented on June 20, 2024

From [email protected] on February 28, 2010 17:01:03

Is this fixed? I don't see any errors from test_zombie_process on my Windows machine

from psutil.

giampaolo avatar giampaolo commented on June 20, 2024

From [email protected] on March 01, 2010 00:19:19

Yes, it's fixed. We are now using GetExitProcess() every time we use OpenProcess(),
which seems the right thing to do.

Status: Fixed

from psutil.

giampaolo avatar giampaolo commented on June 20, 2024

From g.rodola on March 02, 2013 03:47:08

Updated csets after the SVN -> Mercurial migration: r246 == revision 1cd2a04e4049 r512 == revision 27636ff3db58

from psutil.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.