Exemple #1
0
 def test_kill(self):
     p = CPopen(["sleep", "1"],
                stdin=None,
                stdout=subprocess.PIPE,
                stderr=subprocess.PIPE)
     p.kill()
     list(cmdutils.receive(p))
     self.assertEqual(p.returncode, -signal.SIGKILL)
Exemple #2
0
 def test_no_fds(self):
     p = CPopen(["sleep", "1"], stdin=None, stdout=None, stderr=None)
     try:
         with self.assertRaises(cmdutils.TimeoutExpired):
             for _ in cmdutils.receive(p, 0.5):
                 pass
     finally:
         p.kill()
         p.wait()
Exemple #3
0
 def test_without_affinity(self):
     args = [EXT_SLEEP, "3"]
     popen = Popen(args, close_fds=True)
     stats = proc.pidstat(popen.pid)
     pid = int(stats.pid)
     # procName comes in the format of (procname)
     name = stats.comm
     self.assertEqual(pid, popen.pid)
     self.assertEqual(name, args[0])
     popen.kill()
     popen.wait()
Exemple #4
0
 def test_timeout_with_data(self):
     p = CPopen(["yes"],
                stdin=None,
                stdout=subprocess.PIPE,
                stderr=subprocess.PIPE)
     try:
         with self.assertRaises(cmdutils.TimeoutExpired):
             for _ in cmdutils.receive(p, 0.5):
                 pass
     finally:
         p.kill()
         p.wait()
Exemple #5
0
 def test_fds_closed(self):
     cmd = [
         "python", "-c",
         "import os, time; os.close(1); os.close(2); time.sleep(1)"
     ]
     p = CPopen(cmd,
                stdin=None,
                stdout=subprocess.PIPE,
                stderr=subprocess.PIPE)
     try:
         with self.assertRaises(cmdutils.TimeoutExpired):
             for _ in cmdutils.receive(p, 0.5):
                 pass
     finally:
         p.kill()
         p.wait()
Exemple #6
0
 def test(self):
     sleepProcs = []
     try:
         for i in range(3):
             popen = Popen([EXT_SLEEP, "3"])
             sleepProcs.append(popen)
         # There is no guarantee which process run first after forking a
         # child process, make sure all the children are runing before we
         # look for them.
         time.sleep(0.5)
         pids = proc.pgrep(EXT_SLEEP)
         for popen in sleepProcs:
             self.assertIn(popen.pid, pids)
     finally:
         for popen in sleepProcs:
             popen.kill()
             popen.wait()