Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit a255a72

Browse files
committed
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".
1 parent 99d2fbb commit a255a72

1 file changed

Lines changed: 8 additions & 1 deletion

File tree

Lib/tempfile.py

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -128,6 +128,13 @@ class TemporaryFileWrapper:
128128
In particular, it seeks to automatically remove the file when it is
129129
no longer needed.
130130
"""
131+
132+
# Cache the unlinker so we don't get spurious errors at shutdown
133+
# when the module-level "os" in None'd out. Note that this must
134+
# be referenced as self.unlink, because the name TemporaryFileWrapper
135+
# may also get None'd out before __del__ is called.
136+
unlink = os.unlink
137+
131138
def __init__(self, file, path):
132139
self.file = file
133140
self.path = path
@@ -137,7 +144,7 @@ def close(self):
137144
if not self.close_called:
138145
self.close_called = 1
139146
self.file.close()
140-
os.unlink(self.path)
147+
self.unlink(self.path)
141148

142149
def __del__(self):
143150
self.close()

0 commit comments

Comments
 (0)