def listen(self, factory):
        """
        Implement L{IStreamServerEndpoint.listen} to start listening on, and
        then close, C{self._fileno}.
        """
        if self._used:
            return defer.fail(error.AlreadyListened())
        self._used = True

        try:
            self._setNonBlocking(self.fileno)
            port = self.reactor.adoptStreamPort(
                self.fileno, self.addressFamily, factory)
            self._close(self.fileno)
        except:
            return defer.fail()
        return defer.succeed(port)

        Implement L{IStreamServerEndpoint.listen} to start listening on, and
        then close, C{self._fileno}.
        
stackoverflow/venv/lib/python3.6/site-packages/twisted/internet/endpoints.py