title: how to call a callback function after certain amount of time
body: <p>I'm using Twisted along with Txmongo lib.
  In the following function, I want to invoke cancelTest() 5 secs later. But the code does not work. How can I make it work?</p>
  
  <pre><code>from twisted.internet import task
  
  def diverge(self, d):
      if d == 'Wait':
          self.flag = 1
          # self.timeInit = time.time()
          clock = task.Clock()
          for ip in self.ips:
              if self.factory.dictQueue.get(ip) is not None:
                  self.factory.dictQueue[ip].append(self)
              else:
                  self.factory.dictQueue[ip] = deque([self])
                  # self.factory.dictQueue[ip].append(self)
  
          log.msg("-----------------the queue after wait")
          log.msg(self.factory.dictQueue)
  ###############################HERE, this does not work
          self.dtime = task.deferLater(clock, 5, self.printData)
  #############################
          self.dtime.addCallback(self.cancelTest)
          self.dtime.addErrback(log.err)
      else:
          self.cancelTimeOut()
          d.addCallback(self.dispatch)
          d.addErrback(log.err)
  
  
  
  def sendBackIP(self):
      self.ips.pop(0)
      log.msg("the IPs: %s" % self.ips)
  
      d = self.factory.service.checkResource(self.ips)
  
      d.addCallback(self.diverge) ###invoke above function
      log.msg("the result from checkResource: ")
      log.msg()
  </code></pre>