[PATCH 5 of 7] profile: close 'fp' on error within '__enter__'

Sean Farley sean at farley.io
Mon Jun 12 22:10:50 EDT 2017


Pierre-Yves David <pierre-yves.david at ens-lyon.org> writes:

> # HG changeset patch
> # User Pierre-Yves David <pierre-yves.david at octobus.net>
> # Date 1497280901 -7200
> #      Mon Jun 12 17:21:41 2017 +0200
> # Node ID 6db777ef801754d7f97006f865c41408f3bfc300
> # Parent  0f3d18d09dd1c744a1158b1d2b6b881f87fac391
> # 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 6db777ef8017
> profile: close 'fp' on error within '__enter__'
>
> Previously, error when initialying the profiler would forgot to explicitly
> close the file. Thank goes to Yuya Nishihara for spotting this.
>
> diff --git a/mercurial/profiling.py b/mercurial/profiling.py
> --- a/mercurial/profiling.py
> +++ b/mercurial/profiling.py
> @@ -188,7 +188,7 @@ class profile(object):
>  
>          self._output = self._ui.config('profiling', 'output')
>  
> -        if True:
> +        try:
>              if self._output == 'blackbox':
>                  self._fp = util.stringio()
>              elif self._output:
> @@ -209,6 +209,9 @@ class profile(object):
>  
>              self._profiler = proffn(self._ui, self._fp)
>              self._profiler.__enter__()
> +        except: # re-raises
> +            self._closefp

I think you mean self._closefp() here; will fix in-flight.
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 800 bytes
Desc: not available
URL: <http://www.mercurial-scm.org/pipermail/mercurial-devel/attachments/20170612/c3d9fd81/attachment.sig>


More information about the Mercurial-devel mailing list