def METHOD_NAME(self, stats=True):
    profile = self.profile
    if self._current_f is None:
        uuid = uuid4()
        self._current_f = f"{self.name}_{MPI.get_rank()}_{uuid}"
    if stats:
        self.profile.dump_stats(f"{self._current_f}_{self._flushcounter}.prf")
        self._flushcounter += 1
    try:
        del self.profile
        with open(f"{self._current_f}.pkl", "wb") as f:
            pickle.dump(self, f)
    except Exception as e:
        warnings.warn(f"Could not store profile: {e}")
    finally:
        self.profile = profile