summaryrefslogtreecommitdiffstats
path: root/Tools/scripts/gprof2html.py
diff options
context:
space:
mode:
authorSerhiy Storchaka <storchaka@gmail.com>2019-03-30 06:32:18 (GMT)
committerGitHub <noreply@github.com>2019-03-30 06:32:18 (GMT)
commitafbb7a371fb44edc731344eab5b474ad8f7b57d7 (patch)
treebf32e3e6a14a508ee67f0f08e072ffff6ba895df /Tools/scripts/gprof2html.py
parent2524fdefc9bb2a97b99319190aeb23703079ad4c (diff)
downloadcpython-afbb7a371fb44edc731344eab5b474ad8f7b57d7.zip
cpython-afbb7a371fb44edc731344eab5b474ad8f7b57d7.tar.gz
cpython-afbb7a371fb44edc731344eab5b474ad8f7b57d7.tar.bz2
bpo-22831: Use "with" to avoid possible fd leaks in tools (part 1). (GH-10926)
Diffstat (limited to 'Tools/scripts/gprof2html.py')
-rwxr-xr-xTools/scripts/gprof2html.py20
1 files changed, 11 insertions, 9 deletions
diff --git a/Tools/scripts/gprof2html.py b/Tools/scripts/gprof2html.py
index 4ca705c..b14def4 100755
--- a/Tools/scripts/gprof2html.py
+++ b/Tools/scripts/gprof2html.py
@@ -28,14 +28,7 @@ def add_escapes(filename):
for line in fp:
yield html.escape(line)
-
-def main():
- filename = "gprof.out"
- if sys.argv[1:]:
- filename = sys.argv[1]
- outputfilename = filename + ".html"
- input = add_escapes(filename)
- output = open(outputfilename, "w")
+def gprof2html(input, output, filename):
output.write(header % filename)
for line in input:
output.write(line)
@@ -78,7 +71,16 @@ def main():
part = '<a href="#call:%s">%s</a>' % (part, part)
output.write(part)
output.write(trailer)
- output.close()
+
+
+def main():
+ filename = "gprof.out"
+ if sys.argv[1:]:
+ filename = sys.argv[1]
+ outputfilename = filename + ".html"
+ input = add_escapes(filename)
+ with open(outputfilename, "w") as output:
+ gprof2html(input, output, filename)
webbrowser.open("file:" + os.path.abspath(outputfilename))
if __name__ == '__main__':