Fixed leaked file handle on gprof2dot profiling output
@@ -76,9 +76,9 @@ def __call__(self, request):
if not gprof2dot_path.exists():
raise Exception('gprof2dot not found. Please install it to use the graph feature.')
- gprof2dot = subprocess.Popen(
+ with subprocess.Popen(
(sys.executable, gprof2dot_path, '-f', 'pstats', stats_dump.name), stdout=subprocess.PIPE
- )
+ ) as gprof2dot:
response['Content-Type'] = 'image/svg+xml'
@@ -90,6 +90,8 @@ def __call__(self, request):
response['Content-Disposition'] = "attachment; filename=gprof2dot-graph.txt"
response.content = subprocess.check_output('tee', stdin=gprof2dot.stdout)
+ gprof2dot.wait()
+
elif prof_command == 'snake':
# noinspection PyPackageRequirements
try:
