def close(self, timeout=None):
    """ blocking call, return after close/cancel is done.
    """
    undoneJobs = []
    self._condition.acquire()
    if self._status == 'DONE':
      self._condition.release()
      return
    
    self._status = 'DONE'
    self._condition.notifyAll()
    while not self._queue.empty():
      undoneJobs.append(self._queue.get())
    self._condition.release()
    self.join(timeout)
    return undoneJobs
 blocking call, return after close/cancel is done.
    
recipes/Python/577505_Command_Threads/recipe-577505.py