def close(self):
        """Flushes the pending events and closes the writer after it is done."""
        self.flush()
        if self._recordio_writer is not None:
            self._recordio_writer.close()
            self._recordio_writer = None