Richard Oudkerk added the comment: An alternative would be to use weakref.finalize() which would guarantee that cleanup happens before any purging occurs. That would allow the use of shutil:
class TemporaryDirectory(object): def __init__(self, suffix="", prefix=template, dir=None): self.name = mkdtemp(suffix, prefix, dir) self._cleanup = weakref.finalize(self, shutil.rmtree, self.name) def __enter__(self): return self.name def __exit__(self, exc, value, tb): self._cleanup() def cleanup(self): self._cleanup() ---------- nosy: +sbt _______________________________________ Python tracker <rep...@bugs.python.org> <http://bugs.python.org/issue19077> _______________________________________ _______________________________________________ Python-bugs-list mailing list Unsubscribe: https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com