Skip to content

Commit

Permalink
fix #1098: Windows: Process.wait() may return sooner, when the PID is…
Browse files Browse the repository at this point in the history
… still alive
  • Loading branch information
giampaolo committed May 30, 2017
1 parent 5caa045 commit 70fff51
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 5 deletions.
4 changes: 3 additions & 1 deletion HISTORY.rst
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,6 @@

**Bug fixes**

- 1093_: [SunOS] memory_maps() shows wrong 64 bit addresses
- 1007_: [Windows] boot_time() can have a 1 sec fluctuation between calls; the
value of the first call is now cached so that boot_time() always returns the
same value if fluctuation is <= 1 second.
Expand Down Expand Up @@ -75,6 +74,9 @@
- 1085_: cpu_count() return value is now checked and forced to None if <= 1.
- 1087_: Process.cpu_percent() guard against cpu_count() returning None and
assumes 1 instead.
- 1093_: [SunOS] memory_maps() shows wrong 64 bit addresses.
- 1098_: [Windows] Process.wait() may erroneously return sooner, when the PID
is still alive.

**Porting notes**

Expand Down
2 changes: 2 additions & 0 deletions psutil/_psutil_windows.c
Original file line number Diff line number Diff line change
Expand Up @@ -398,7 +398,9 @@ psutil_proc_wait(PyObject *self, PyObject *args) {
CloseHandle(hProcess);
return PyErr_SetFromWindowsErr(GetLastError());
}

CloseHandle(hProcess);

#if PY_MAJOR_VERSION >= 3
return PyLong_FromLong((long) ExitCode);
#else
Expand Down
11 changes: 7 additions & 4 deletions psutil/_pswindows.py
Original file line number Diff line number Diff line change
Expand Up @@ -791,10 +791,13 @@ def wait(self, timeout=None):
else:
# WaitForSingleObject() expects time in milliseconds
cext_timeout = int(timeout * 1000)
ret = cext.proc_wait(self.pid, cext_timeout)
if ret == WAIT_TIMEOUT:
raise TimeoutExpired(timeout, self.pid, self._name)
return ret
while True:
ret = cext.proc_wait(self.pid, cext_timeout)
if ret == WAIT_TIMEOUT:
raise TimeoutExpired(timeout, self.pid, self._name)
if timeout is None and pid_exists(self.pid):
continue
return ret

@wrap_exceptions
def username(self):
Expand Down

0 comments on commit 70fff51

Please sign in to comment.