]> granicus.if.org Git - python/commitdiff
TemporaryFileWrapper: cache the value of os.unlink for use by __del__,
authorTim Peters <tim.peters@gmail.com>
Tue, 18 Dec 2001 22:32:40 +0000 (22:32 +0000)
committerTim Peters <tim.peters@gmail.com>
Tue, 18 Dec 2001 22:32:40 +0000 (22:32 +0000)
to prevent mysterious errors at shutdown due to "os.unlink" turning into
"None.unlink".

Lib/tempfile.py

index 96245d8c396f9d1470f2b0cf1d546276914cd81f..d4880637f08d2bcc9a54856d4e4bf0806e4bb906 100644 (file)
@@ -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()