code: def detach(self, result, sync=True):
          
          count = 0
  
          if sync and result.attached():
              self.send()
              fetch = self.fetch
              while result.attached():
                  count += fetch()
  
          if self._last_result is result:
              self._last_result = None
              if not self.has_transaction():
                  self._disconnect(sync=False)
  
          result._session = None
          return count
docs: Detach a result from this session by fetching and buffering any
          remaining records.
  
          :param result:
          :param sync:
          :returns: number of records fetched