'The win32 handles should be properly closed when the process exits.'

def test_closeHandles(self):

    import win32api
    connected = defer.Deferred()
    ended = defer.Deferred()
    class SimpleProtocol(protocol.ProcessProtocol, ):
        '\n                                                A    protocol    that    fires    deferreds    when    connected    and    disconnected.\n                                                '
        def makeConnection(self, transport):
            connected.callback(transport)
        def processEnded(self, reason):
            ended.callback(None)
    p = SimpleProtocol()
    pyArgs = [pyExe, '-u', '-c', "print('hello')"]
    proc = reactor.spawnProcess(p, pyExe, pyArgs)
    def cbConnected(transport):
        self.assertIs(transport, proc)
        win32api.GetHandleInformation(proc.hProcess)
        win32api.GetHandleInformation(proc.hThread)
        self.hProcess = proc.hProcess
        self.hThread = proc.hThread
    connected.addCallback(cbConnected)
    def checkTerminated(ignored):
        self.assertIsNone(proc.pid)
        self.assertIsNone(proc.hProcess)
        self.assertIsNone(proc.hThread)
        self.assertRaises(win32api.error, win32api.GetHandleInformation, self.hProcess)
        self.assertRaises(win32api.error, win32api.GetHandleInformation, self.hThread)
    ended.addCallback(checkTerminated)
    return defer.gatherResults([connected, ended])
