From 46ba6c8563922f043cad6423202ee0119614c807 Mon Sep 17 00:00:00 2001 From: Serhiy Storchaka Date: Sat, 4 Apr 2015 11:01:02 +0300 Subject: Issue #22831: Use "with" to avoid possible fd leaks. --- Lib/cgitb.py | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) (limited to 'Lib/cgitb.py') diff --git a/Lib/cgitb.py b/Lib/cgitb.py index 6eb52e764e..b29110018c 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 -- cgit v1.2.1