def test_build_process_can_create_processes(self): p0 = BuildProcess([sys.executable, echo_hello], '.') p0.wait() self.assertEqual(p0.readline().strip(), b'hello') self.assertEqual(p0.readline().strip(), b'')
def test_terminate_job_object(self): p0 = BuildProcess([sys.executable, run_sub_process], '.') time.sleep(.3) parent = psutil.Process(p0.pid) children = parent.children() p0.kill_job() p0.wait() self.assertFalse(parent.is_running()) self.assertEqual([c.is_running() for c in children], [False])
def test_terminate_process_group(self): p0 = BuildProcess([sys.executable, run_sub_process], '.') time.sleep(.3) parent = psutil.Process(p0.pid) children = parent.children() parent_pgid = os.getpgid(parent.pid) for child in children: self.assertEqual(parent_pgid, os.getpgid(child.pid)) p0.kill_pg() p0.wait() self.assertFalse(parent.is_running()) self.assertEqual([c.is_running() for c in children], [False])
def test_terminate_process_group_naive(self): p0 = BuildProcess([sys.executable, run_sub_process], '.') time.sleep(.3) parent = psutil.Process(p0.pid) children = parent.children() parent.kill() p0.wait() self.assertFalse(parent.is_running()) self.assertEqual([c.is_running() for c in children], [True]) for c in children: if c.is_running(): c.kill()
def test_quiet(self): for quiet in (True, False): cmd = [ 'echo', 'ncurses-5.9-1. 9% |## | ETA: 0:00:00 76.02 MB/s\r' ] if os.name == 'nt': cmd = ['cmd.exe', '/c'] + cmd p0 = BuildProcess(cmd, '.') output = io.BytesIO() read_with_timeout(p0, output, timeout=20, quiet=quiet) out = output.getvalue() if quiet: self.assertEqual(b'', out) else: self.assertIn(b'ncurses', out)