code: def _timeoutDeferred(deferred, timeout):
      
      delayedCall = reactor.callLater(timeout, deferred.cancel)
      def gotResult(result):
          if delayedCall.active():
              delayedCall.cancel()
          return result
      deferred.addBoth(gotResult)
docs: Cancels the given deferred after the given time, if it has not yet callbacked/errbacked it.