summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorGiampaolo Rodola <g.rodola@gmail.com>2017-01-31 15:39:53 +0100
committerGiampaolo Rodola <g.rodola@gmail.com>2017-01-31 15:39:53 +0100
commit88e96ffaafb8422121cd98775a408cd13bdbd572 (patch)
treee0ef6eb96f338ad703870893af3fd89f38a35f18
parent8291347dd0f89131800983e6412b534911df695c (diff)
downloadpsutil-88e96ffaafb8422121cd98775a408cd13bdbd572.tar.gz
#fix 960 / Popen.wait: return negative exit code if process is killed by a signal
-rw-r--r--HISTORY.rst2
-rw-r--r--psutil/_psposix.py2
-rwxr-xr-xpsutil/tests/test_process.py12
3 files changed, 9 insertions, 7 deletions
diff --git a/HISTORY.rst b/HISTORY.rst
index 782b147c..abd2d456 100644
--- a/HISTORY.rst
+++ b/HISTORY.rst
@@ -20,6 +20,8 @@
- 950_: [Windows] Process.cpu_percent() was calculated incorrectly and showed
higher number than real usage.
- 959_: psutil exception objects could not be pickled.
+- 960_: Popen.wait() did not return the correct negative exit status if process
+ is ``kill()``ed by a signal.
5.0.1
diff --git a/psutil/_psposix.py b/psutil/_psposix.py
index acbc7855..6debdb32 100644
--- a/psutil/_psposix.py
+++ b/psutil/_psposix.py
@@ -110,7 +110,7 @@ def wait_pid(pid, timeout=None):
# process exited due to a signal; return the integer of
# that signal
if os.WIFSIGNALED(status):
- return os.WTERMSIG(status)
+ return -os.WTERMSIG(status)
# process exited using exit(2) system call; return the
# integer exit(2) system call has been called with
elif os.WIFEXITED(status):
diff --git a/psutil/tests/test_process.py b/psutil/tests/test_process.py
index 089809b6..bdbb72a9 100755
--- a/psutil/tests/test_process.py
+++ b/psutil/tests/test_process.py
@@ -104,7 +104,7 @@ class TestProcess(unittest.TestCase):
sig = p.wait()
self.assertFalse(psutil.pid_exists(test_pid))
if POSIX:
- self.assertEqual(sig, signal.SIGKILL)
+ self.assertEqual(sig, -signal.SIGKILL)
def test_terminate(self):
sproc = get_test_subprocess()
@@ -114,7 +114,7 @@ class TestProcess(unittest.TestCase):
sig = p.wait()
self.assertFalse(psutil.pid_exists(test_pid))
if POSIX:
- self.assertEqual(sig, signal.SIGTERM)
+ self.assertEqual(sig, -signal.SIGTERM)
def test_send_signal(self):
sig = signal.SIGKILL if POSIX else signal.SIGTERM
@@ -124,7 +124,7 @@ class TestProcess(unittest.TestCase):
exit_sig = p.wait()
self.assertFalse(psutil.pid_exists(p.pid))
if POSIX:
- self.assertEqual(exit_sig, sig)
+ self.assertEqual(exit_sig, -sig)
#
sproc = get_test_subprocess()
p = psutil.Process(sproc.pid)
@@ -155,7 +155,7 @@ class TestProcess(unittest.TestCase):
p.kill()
code = p.wait()
if POSIX:
- self.assertEqual(code, signal.SIGKILL)
+ self.assertEqual(code, -signal.SIGKILL)
else:
self.assertEqual(code, 0)
self.assertFalse(p.is_running())
@@ -165,7 +165,7 @@ class TestProcess(unittest.TestCase):
p.terminate()
code = p.wait()
if POSIX:
- self.assertEqual(code, signal.SIGTERM)
+ self.assertEqual(code, -signal.SIGTERM)
else:
self.assertEqual(code, 0)
self.assertFalse(p.is_running())
@@ -231,7 +231,7 @@ class TestProcess(unittest.TestCase):
else:
break
if POSIX:
- self.assertEqual(code, signal.SIGKILL)
+ self.assertEqual(code, -signal.SIGKILL)
else:
self.assertEqual(code, 0)
self.assertFalse(p.is_running())