[PATCH 2 of 7] profile: use explicit logic to control file closing
Pierre-Yves David
pierre-yves.david at ens-lyon.org
Mon Jun 12 16:17:46 UTC 2017
# HG changeset patch
# User Pierre-Yves David <pierre-yves.david at octobus.net>
# Date 1497280496 -7200
# Mon Jun 12 17:14:56 2017 +0200
# Node ID a9f13910ea2972e82c0809fb1f46d42baa1f44d3
# Parent ffbf377689412a98a606c7576c3a40977f6d34f2
# EXP-Topic profile
# Available At https://www.mercurial-scm.org/repo/users/marmoute/mercurial/
# hg pull https://www.mercurial-scm.org/repo/users/marmoute/mercurial/ -r a9f13910ea29
profile: use explicit logic to control file closing
We make the decision to close 'fp' more explicit instead of relying on the
implication of other variable. This makes the overall logic more robust.
diff --git a/mercurial/profiling.py b/mercurial/profiling.py
--- a/mercurial/profiling.py
+++ b/mercurial/profiling.py
@@ -151,6 +151,7 @@ class profile(object):
self._ui = ui
self._output = None
self._fp = None
+ self._fpdoclose = True
self._profiler = None
self._enabled = enabled
self._entered = False
@@ -193,6 +194,7 @@ class profile(object):
path = self._ui.expandpath(self._output)
self._fp = open(path, 'wb')
else:
+ self._fpdoclose = False
self._fp = self._ui.ferr
if proffn is not None:
@@ -221,4 +223,5 @@ class profile(object):
self._closefp()
def _closefp(self):
- self._fp.close()
+ if self._fpdoclose and self._fp is not None:
+ self._fp.close()
More information about the Mercurial-devel
mailing list