Skip to content

Commit

Permalink
#fix 960 / Popen.wait: return negative exit code if process is killed…
Browse files Browse the repository at this point in the history
… by a signal
  • Loading branch information
giampaolo committed Jan 31, 2017
1 parent 8291347 commit 88e96ff
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 7 deletions.
2 changes: 2 additions & 0 deletions HISTORY.rst
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion psutil/_psposix.py
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,7 @@ def waitcall():
# 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):
Expand Down
12 changes: 6 additions & 6 deletions psutil/tests/test_process.py
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,7 @@ def test_kill(self):
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()
Expand All @@ -114,7 +114,7 @@ def test_terminate(self):
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
Expand All @@ -124,7 +124,7 @@ def test_send_signal(self):
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)
Expand Down Expand Up @@ -155,7 +155,7 @@ def test_wait(self):
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())
Expand All @@ -165,7 +165,7 @@ def test_wait(self):
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())
Expand Down Expand Up @@ -231,7 +231,7 @@ def test_wait_timeout_0(self):
else:
break
if POSIX:
self.assertEqual(code, signal.SIGKILL)
self.assertEqual(code, -signal.SIGKILL)
else:
self.assertEqual(code, 0)
self.assertFalse(p.is_running())
Expand Down

0 comments on commit 88e96ff

Please sign in to comment.