def test_nonReentrantCallbacks(self):
        """
        A callback added to a L{Deferred} by a callback on that L{Deferred}
        should not be executed until the running callback returns.
        """
        deferred = defer.Deferred()
        called = []
        def callback2(result):
            called.append(2)
        def callback1(result):
            called.append(1)
            deferred.addCallback(callback2)
            self.assertEqual(called, [1])
        deferred.addCallback(callback1)
        deferred.callback(None)
        self.assertEqual(called, [1, 2])

        A callback added to a L{Deferred} by a callback on that L{Deferred}
        should not be executed until the running callback returns.
        
stackoverflow/venv/lib/python3.6/site-packages/twisted/test/test_defer.py