def doit(self, fd):
        """
        Create a child process and close one of its output descriptors using
        L{IProcessTransport.closeStdout} or L{IProcessTransport.closeStderr}.
        Return a L{Deferred} which fires after verifying that the descriptor was
        really closed.
        """
        p = ClosingPipesProcessProtocol(True)
        self.assertFailure(p.deferred, error.ProcessTerminated)
        p.deferred.addCallback(self._endProcess, p)
        reactor.spawnProcess(
            p, pyExe, [
                pyExe, b'-u', b'-c',
                networkString('try: input = raw_input\n'
                'except NameError: pass\n'
                'input()\n'
                'import sys, os, time\n'
                # Give the system a bit of time to notice the closed
                # descriptor.  Another option would be to poll() for HUP
                # instead of relying on an os.write to fail with SIGPIPE.
                # However, that wouldn't work on macOS (or Windows?).
                'for i in range(1000):\n'
                '    os.write(%d, b"foo\\n")\n'
                '    time.sleep(0.01)\n'
                'sys.exit(42)\n' % (fd,))
                ],
            env=None)

        if fd == 1:
            p.transport.closeStdout()
        elif fd == 2:
            p.transport.closeStderr()
        else:
            raise RuntimeError

        # Give the close time to propagate
        p.transport.write(b'go\n')

        # make the buggy case not hang
        p.transport.closeStdin()
        return p.deferred

        Create a child process and close one of its output descriptors using
        L{IProcessTransport.closeStdout} or L{IProcessTransport.closeStderr}.
        Return a L{Deferred} which fires after verifying that the descriptor was
        really closed.
        
stackoverflow/venv/lib/python3.6/site-packages/twisted/test/test_process.py