diff options
author | Tim Peters <tim.peters@gmail.com> | 2001-12-18 22:32:40 (GMT) |
---|---|---|
committer | Tim Peters <tim.peters@gmail.com> | 2001-12-18 22:32:40 (GMT) |
commit | a255a72f0a5d33c1d28547dfb2f7d320a2ca1773 (patch) | |
tree | e6fdc38e247b1742a9901edd9ff0a6ebc1ca38a0 /Lib | |
parent | 99d2fbb8236dc792d7e3762cf1d7419405db4752 (diff) | |
download | cpython-a255a72f0a5d33c1d28547dfb2f7d320a2ca1773.zip cpython-a255a72f0a5d33c1d28547dfb2f7d320a2ca1773.tar.gz cpython-a255a72f0a5d33c1d28547dfb2f7d320a2ca1773.tar.bz2 |
TemporaryFileWrapper: cache the value of os.unlink for use by __del__,
to prevent mysterious errors at shutdown due to "os.unlink" turning into
"None.unlink".
Diffstat (limited to 'Lib')
-rw-r--r-- | Lib/tempfile.py | 9 |
1 files changed, 8 insertions, 1 deletions
diff --git a/Lib/tempfile.py b/Lib/tempfile.py index 96245d8..d488063 100644 --- a/Lib/tempfile.py +++ b/Lib/tempfile.py @@ -128,6 +128,13 @@ class TemporaryFileWrapper: In particular, it seeks to automatically remove the file when it is no longer needed. """ + + # Cache the unlinker so we don't get spurious errors at shutdown + # when the module-level "os" in None'd out. Note that this must + # be referenced as self.unlink, because the name TemporaryFileWrapper + # may also get None'd out before __del__ is called. + unlink = os.unlink + def __init__(self, file, path): self.file = file self.path = path @@ -137,7 +144,7 @@ class TemporaryFileWrapper: if not self.close_called: self.close_called = 1 self.file.close() - os.unlink(self.path) + self.unlink(self.path) def __del__(self): self.close() |