def test_clientConnectionLost(self):
        """
        Test that if the L{reconnecting} flag is passed with a True value then
        a remote call made from a disconnection notification callback gets a
        result successfully.
        """
        class ReconnectOnce(pb.PBClientFactory):
            reconnectedAlready = False

            def clientConnectionLost(self, connector, reason):
                reconnecting = not self.reconnectedAlready
                self.reconnectedAlready = True
                result = pb.PBClientFactory.clientConnectionLost(
                    self, connector, reason, reconnecting)
                if reconnecting:
                    connector.connect()
                return result

        self.clientFactory = ReconnectOnce()
        self.establishClientAndServer()

        rootObjDeferred = self.clientFactory.getRootObject()

        def gotRootObject(rootObj):
            self.assertIsInstance(rootObj, pb.RemoteReference)

            d = Deferred()
            rootObj.notifyOnDisconnect(d.callback)
            # request a disconnection
            self.clientFactory.disconnect()
            self.completeClientLostConnection()

            def disconnected(ign):
                d = self.clientFactory.getRootObject()

                def gotAnotherRootObject(anotherRootObj):
                    self.assertIsInstance(anotherRootObj, pb.RemoteReference)
                    d = Deferred()
                    anotherRootObj.notifyOnDisconnect(d.callback)
                    self.clientFactory.disconnect()
                    self.completeClientLostConnection()
                    return d
                return d.addCallback(gotAnotherRootObject)
            return d.addCallback(disconnected)

        return rootObjDeferred.addCallback(gotRootObject)

        Test that if the L{reconnecting} flag is passed with a True value then
        a remote call made from a disconnection notification callback gets a
        result successfully.
        
stackoverflow/venv/lib/python3.6/site-packages/twisted/spread/test/test_pb.py