Mercurial > public > mercurial-scm > hg
comparison mercurial/profiling.py @ 32810:6675d23da748
profile: properly propagate exception from the sub-context manager
Context manager has a mechanism to control extension propagation. It is not
used by profiling right now, but making the code correct will help prevent bug
in the future.
author | Pierre-Yves David <pierre-yves.david@octobus.net> |
---|---|
date | Mon, 12 Jun 2017 17:24:10 +0200 |
parents | 062eb859d3ee |
children | cb6436e051ca |
comparison
equal
deleted
inserted
replaced
32809:062eb859d3ee | 32810:6675d23da748 |
---|---|
212 except: # re-raises | 212 except: # re-raises |
213 self._closefp() | 213 self._closefp() |
214 raise | 214 raise |
215 | 215 |
216 def __exit__(self, exception_type, exception_value, traceback): | 216 def __exit__(self, exception_type, exception_value, traceback): |
217 propagate = None | |
217 if self._profiler is not None: | 218 if self._profiler is not None: |
218 self._profiler.__exit__(exception_type, exception_value, traceback) | 219 propagate = self._profiler.__exit__(exception_type, exception_value, |
220 traceback) | |
219 if self._output == 'blackbox': | 221 if self._output == 'blackbox': |
220 val = 'Profile:\n%s' % self._fp.getvalue() | 222 val = 'Profile:\n%s' % self._fp.getvalue() |
221 # ui.log treats the input as a format string, | 223 # ui.log treats the input as a format string, |
222 # so we need to escape any % signs. | 224 # so we need to escape any % signs. |
223 val = val.replace('%', '%%') | 225 val = val.replace('%', '%%') |
224 self._ui.log('profile', val) | 226 self._ui.log('profile', val) |
225 self._closefp() | 227 self._closefp() |
228 return propagate | |
226 | 229 |
227 def _closefp(self): | 230 def _closefp(self): |
228 if self._fpdoclose and self._fp is not None: | 231 if self._fpdoclose and self._fp is not None: |
229 self._fp.close() | 232 self._fp.close() |