code: def generate(self, callback=None, interval=0):
          
          if self.path is None:
              raise RuntimeError('generate() called with no path specified')
          elif self.size <= 0:
              raise error.PathEmptyError(self.path)
          elif not os.path.exists(self.path):
              raise error.PathNotFoundError(self.path)
  
          if callback is not None:
              cancel = lambda *status: callback(*status) is not None
          else:
              cancel = lambda *status: False
  
          if os.path.isfile(self.path):
              pieces = self._set_pieces_singlefile()
          elif os.path.isdir(self.path):
              pieces = self._set_pieces_multifile()
  
          # Iterate over hashed pieces and send status information
          last_cb_call = 0
          for filepath,pieces_done,pieces_total in pieces:
              now = time.time()
              if now - last_cb_call >= interval or \
                 pieces_done >= pieces_total:
                  last_cb_call = now
                  if cancel(self, filepath, pieces_done, pieces_total):
                      return False
          return True
docs: Hash pieces and report progress to `callback`
  
          This method sets ``pieces`` in :attr:`metainfo`\ ``['info']`` when all
          pieces are hashed successfully.
  
          :param callable callback: Callable with signature ``(torrent, filepath,
              pieces_done, pieces_total)``; if `callback` returns anything else
              than None, hashing is canceled
  
          :param float interval: Minimum number of seconds between calls to
              `callback` (if 0, `callback` is called once per piece)
          :raises PathEmptyError: if :attr:`path` contains only empty
              files/directories
          :raises PathNotFoundError: if :attr:`path` does not exist
          :raises ReadError: if :attr:`path` or any file beneath it is not
              readable
  
          :return: ``True`` if all pieces were successfully hashed, ``False``
              otherwise