summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorGiampaolo Rodola <g.rodola@gmail.com>2017-05-30 12:02:15 +0200
committerGiampaolo Rodola <g.rodola@gmail.com>2017-05-30 12:02:15 +0200
commit70fff514f12c7f2789e5d8e26140a274dc64f841 (patch)
treefb525560948333272abc2b3677e1138acc7226f6
parent5caa045f1f8d06888717fa5422b40367b6db3495 (diff)
downloadpsutil-70fff514f12c7f2789e5d8e26140a274dc64f841.tar.gz
fix #1098: Windows: Process.wait() may return sooner, when the PID is still alive
-rw-r--r--HISTORY.rst4
-rw-r--r--psutil/_psutil_windows.c2
-rw-r--r--psutil/_pswindows.py11
3 files changed, 12 insertions, 5 deletions
diff --git a/HISTORY.rst b/HISTORY.rst
index 2e73df49..99cb6f89 100644
--- a/HISTORY.rst
+++ b/HISTORY.rst
@@ -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.
@@ -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**
diff --git a/psutil/_psutil_windows.c b/psutil/_psutil_windows.c
index 9c8782e3..9e16d207 100644
--- a/psutil/_psutil_windows.c
+++ b/psutil/_psutil_windows.c
@@ -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
diff --git a/psutil/_pswindows.py b/psutil/_pswindows.py
index 6d0679d6..ff868f2e 100644
--- a/psutil/_pswindows.py
+++ b/psutil/_pswindows.py
@@ -791,10 +791,13 @@ class Process(object):
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):