Exemplo n.º 1
0
    def testPopenCloseFds(self):
        r, w = filedes.pipe()

        try:
            # Create a subprocess that prints and blocks waiting for input
            p = Popen("echo ok; read foo", shell=True,
                      stdin=PIPE, stdout=PIPE, stderr=STDOUT,
                      close_fds=True)
            try:
                # Wait for the process to let us know it's alive
                ready = p.stdout.read(3)
                self.assertEquals(ready, "ok\n")

                # Get the list of FDs of the remote process
                remote_fds = get_open_fds(p.pid)

                # Make sure the read fd persisted, but the write fd was not.
                self.assertNotIn(r, remote_fds)
                self.assertNotIn(w, remote_fds)

                # Now send some output to the remote process to unblock it
                p.stdin.write("ok\n")
                p.stdin.flush()

                # Wait for it to shutdown
                self.assertEquals(p.wait(), 0)
            finally:
                # Popen does not close PIPE fds on process shutdown
                # automatically, even if there's no data in it.  Since the
                # exception context is propagated to the test cases' tearDown,
                # the popen's pipes will show up as a leak
                del p
        finally:
            r.close()
            w.close()
Exemplo n.º 2
0
 def testIterateTwice(self):
     it = filedes.pipe()
     l1 = list(it)
     l2 = list(it)
     try:
         self.assertItemsEqual(l1, l2)
     finally:
         for fd in l1:
             fd.close()
Exemplo n.º 3
0
 def testIterateTwice(self):
     it = filedes.pipe()
     l1 = list(it)
     l2 = list(it)
     try:
         self.assertItemsEqual(l1, l2)
     finally:
         for fd in l1:
             fd.close()
Exemplo n.º 4
0
 def testPipe(self):
     import filedes
     self.checkSubprocessFDs(filedes.pipe())
Exemplo n.º 5
0
 def testPipe(self):
     import filedes
     self.checkSubprocessFDs(filedes.pipe())
Exemplo n.º 6
0
 def testDup2(self):
     r, w = filedes.pipe()
     r2 = r.dup(63)
     self.dupTestCommon(r, w, r2)
Exemplo n.º 7
0
 def testPipeConstructor(self):
     r, w = filedes.pipe()
     self.assertIsInstance(r, LocalFileDescriptor)
     self.assertIsInstance(w, LocalFileDescriptor)
     r.close()
     w.close()
Exemplo n.º 8
0
 def testDup(self):
     r, w = filedes.pipe()
     r2 = r.dup()
     self.dupTestCommon(r, w, r2)
Exemplo n.º 9
0
 def testPipeConstructor(self):
     r, w = filedes.pipe()
     self.assertIsInstance(r, LocalFileDescriptor)
     self.assertIsInstance(w, LocalFileDescriptor)
     r.close()
     w.close()