summaryrefslogtreecommitdiffstats
path: root/Lib/cgitb.py
diff options
context:
space:
mode:
authorSerhiy Storchaka <storchaka@gmail.com>2015-04-04 08:01:02 (GMT)
committerSerhiy Storchaka <storchaka@gmail.com>2015-04-04 08:01:02 (GMT)
commit46ba6c8563922f043cad6423202ee0119614c807 (patch)
tree4523d1a3665af25ef77898f7d2da186fbdca8ce7 /Lib/cgitb.py
parentae2d667ae83548029fed7244619fadd7f625cb24 (diff)
downloadcpython-46ba6c8563922f043cad6423202ee0119614c807.zip
cpython-46ba6c8563922f043cad6423202ee0119614c807.tar.gz
cpython-46ba6c8563922f043cad6423202ee0119614c807.tar.bz2
Issue #22831: Use "with" to avoid possible fd leaks.
Diffstat (limited to 'Lib/cgitb.py')
-rw-r--r--Lib/cgitb.py5
1 files changed, 2 insertions, 3 deletions
diff --git a/Lib/cgitb.py b/Lib/cgitb.py
index 6eb52e7..b291100 100644
--- a/Lib/cgitb.py
+++ b/Lib/cgitb.py
@@ -294,9 +294,8 @@ class Hook:
(fd, path) = tempfile.mkstemp(suffix=suffix, dir=self.logdir)
try:
- file = os.fdopen(fd, 'w')
- file.write(doc)
- file.close()
+ with os.fdopen(fd, 'w') as file:
+ file.write(doc)
msg = '%s contains the description of this error.' % path
except:
msg = 'Tried to save traceback to %s, but failed.' % path