Author: Philip Jenvey <[email protected]>
Branch: py3k
Changeset: r84601:263f5c13be5b
Date: 2016-05-22 14:41 -0700
http://bitbucket.org/pypy/pypy/changeset/263f5c13be5b/
Log: cleanup TempoaryDirectorys atexit
diff --git a/lib-python/3/tempfile.py b/lib-python/3/tempfile.py
--- a/lib-python/3/tempfile.py
+++ b/lib-python/3/tempfile.py
@@ -34,6 +34,7 @@
import os as _os
import shutil as _shutil
import errno as _errno
+import weakref as _weakref
from random import Random as _Random
try:
@@ -686,6 +687,7 @@
def __init__(self, suffix="", prefix=template, dir=None):
self.name = mkdtemp(suffix, prefix, dir)
+ _tmpdirs.add(self)
def __repr__(self):
return "<{} {!r}>".format(self.__class__.__name__, self.name)
@@ -714,6 +716,7 @@
def __exit__(self, exc, value, tb):
self.cleanup()
+ _tmpdirs.discard(self)
def __del__(self):
# Issue a ResourceWarning if implicit cleanup needed
@@ -736,10 +739,23 @@
except _OSError:
pass
+_tmpdirs = _weakref.WeakSet()
_is_running = True
+def _tmpdir_cleanup():
+ while _tmpdirs:
+ try:
+ tmpdir = _tmpdirs.pop()
+ except KeyError:
+ break
+ try:
+ tmpdir.cleanup(_warn=True)
+ except:
+ pass
+
def _on_shutdown():
global _is_running
+ _tmpdir_cleanup()
_is_running = False
_atexit.register(_on_shutdown)
_______________________________________________
pypy-commit mailing list
[email protected]
https://mail.python.org/mailman/listinfo/pypy-commit