Beispiel #1
0
 def testBrokenPipe(self):
     p = CPopen(["sleep", "1"])
     try:
         p.send_signal(signal.SIGPIPE)
     finally:
         p.kill()
     p.wait()
     self.assertEqual(p.returncode, -signal.SIGKILL)
Beispiel #2
0
 def testCloseFDs(self):
     with open("/dev/zero") as f:
         p = CPopen(["sleep", "1"], close_fds=True)
         try:
             child_fds = set(os.listdir("/proc/%s/fd" % p.pid))
         finally:
             p.kill()
             p.wait()
         self.assertEqual(child_fds, set(["0", "1", "2"]))
Beispiel #3
0
 def testBrokenPipeSIGPIPERestored(self):
     if not cpopen.SUPPORTS_RESTORE_SIGPIPE:
         raise SkipTest("subprocess module does not support restore_sigpipe")
     p = CPopen(["sleep", "1"], restore_sigpipe=True)
     try:
         p.send_signal(signal.SIGPIPE)
     finally:
         p.kill()
     p.wait()
     self.assertEqual(p.returncode, -signal.SIGPIPE)
Beispiel #4
0
 def testNoCloseFds(self):
     with open("/dev/zero") as f:
         p = CPopen(["sleep", "1"], close_fds=False)
         try:
             child_fds = set(os.listdir("/proc/%s/fd" % p.pid))
         finally:
             p.kill()
             p.wait()
         # We cannot know which fds will be inherited in the child since the
         # test framework may open some fds.
         self.assertTrue(str(f.fileno()) in child_fds)
Beispiel #5
0
 def testInheritParentFdsCloseFds(self):
     # From Python docs: If close_fds is true, all file descriptors except
     # 0, 1 and 2 will be closed before the child process is executed.
     with open("/dev/zero") as f:
         p = CPopen(["sleep", "1"], stdin=None, stdout=None, stderr=None,
                    close_fds=True)
         try:
             child_fds = set(os.listdir("/proc/%s/fd" % p.pid))
         finally:
             p.kill()
             p.wait()
     self.assertEqual(child_fds, set(["0", "1", "2"]))
Beispiel #6
0
 def testInheritParentFds(self):
     # From Python docs: With the default settings of None, no redirection
     # will occur; the child's file handles will be inherited from the
     # parent.
     with open("/dev/zero") as f:
         p = CPopen(["sleep", "1"], stdin=None, stdout=None, stderr=None,
                    close_fds=False)
         try:
             child_fds = set(os.listdir("/proc/%s/fd" % p.pid))
         finally:
             p.kill()
             p.wait()
         expected_fds = set(["0", "1", "2", str(f.fileno())])
     self.assertEqual(child_fds, expected_fds)