mirror of
https://github.com/python/cpython.git
synced 2025-07-30 22:54:16 +00:00
Added kill, terminate and send_signal to subprocess.Popen
The bits and pieces for the Windows side were already in place. The POSIX side is trivial (as usual) and uses os.kill().
This commit is contained in:
parent
c873550737
commit
e74c8f2879
4 changed files with 103 additions and 0 deletions
|
@ -584,6 +584,29 @@ class ProcessTestCase(unittest.TestCase):
|
|||
os.remove(fname)
|
||||
self.assertEqual(rc, 47)
|
||||
|
||||
def test_send_signal(self):
|
||||
p = subprocess.Popen([sys.executable,
|
||||
"-c", "input()"])
|
||||
|
||||
self.assert_(p.poll() is None, p.poll())
|
||||
p.send_signal(signal.SIGINT)
|
||||
self.assertNotEqual(p.wait(), 0)
|
||||
|
||||
def test_kill(self):
|
||||
p = subprocess.Popen([sys.executable,
|
||||
"-c", "input()"])
|
||||
|
||||
self.assert_(p.poll() is None, p.poll())
|
||||
p.kill()
|
||||
self.assertEqual(p.wait(), -signal.SIGKILL)
|
||||
|
||||
def test_terminate(self):
|
||||
p = subprocess.Popen([sys.executable,
|
||||
"-c", "input()"])
|
||||
|
||||
self.assert_(p.poll() is None, p.poll())
|
||||
p.terminate()
|
||||
self.assertEqual(p.wait(), -signal.SIGTERM)
|
||||
|
||||
#
|
||||
# Windows tests
|
||||
|
@ -655,6 +678,29 @@ class ProcessTestCase(unittest.TestCase):
|
|||
' -c "import sys; sys.exit(47)"')
|
||||
self.assertEqual(rc, 47)
|
||||
|
||||
def test_send_signal(self):
|
||||
p = subprocess.Popen([sys.executable,
|
||||
"-c", "input()"])
|
||||
|
||||
self.assert_(p.poll() is None, p.poll())
|
||||
p.send_signal(signal.SIGTERM)
|
||||
self.assertNotEqual(p.wait(), 0)
|
||||
|
||||
def test_kill(self):
|
||||
p = subprocess.Popen([sys.executable,
|
||||
"-c", "input()"])
|
||||
|
||||
self.assert_(p.poll() is None, p.poll())
|
||||
p.kill()
|
||||
self.assertNotEqual(p.wait(), 0)
|
||||
|
||||
def test_terminate(self):
|
||||
p = subprocess.Popen([sys.executable,
|
||||
"-c", "input()"])
|
||||
|
||||
self.assert_(p.poll() is None, p.poll())
|
||||
p.terminate()
|
||||
self.assertNotEqual(p.wait(), 0)
|
||||
|
||||
def test_main():
|
||||
test_support.run_unittest(ProcessTestCase)
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue