# HG changeset patch # User Pierre-Yves David # Date 2017-06-12 15:14:56 # Node ID 2b0fc56840d05a0aabffce75a468dd5d16b0664b # Parent c0b2c8f25ad97868f3272fa790665c2d46f731d7 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()