comparison mercurial/profiling.py @ 32809:062eb859d3ee

profile: close 'fp' in all cases There are no way for this to happen today, but better be safe than sorry, no one know how the code will evolve. We now make sure the file pointer is closed even is profiler is None.
author Pierre-Yves David <pierre-yves.david@octobus.net>
date Mon, 12 Jun 2017 17:25:37 +0200
parents 336700745a5c
children 6675d23da748
comparison
equal deleted inserted replaced
32808:336700745a5c 32809:062eb859d3ee
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 if self._profiler is None: 217 if self._profiler is not None:
218 return 218 self._profiler.__exit__(exception_type, exception_value, traceback)
219 self._profiler.__exit__(exception_type, exception_value, traceback) 219 if self._output == 'blackbox':
220 if self._output == 'blackbox': 220 val = 'Profile:\n%s' % self._fp.getvalue()
221 val = 'Profile:\n%s' % self._fp.getvalue() 221 # ui.log treats the input as a format string,
222 # ui.log treats the input as a format string, 222 # so we need to escape any % signs.
223 # so we need to escape any % signs. 223 val = val.replace('%', '%%')
224 val = val.replace('%', '%%') 224 self._ui.log('profile', val)
225 self._ui.log('profile', val)
226 self._closefp() 225 self._closefp()
227 226
228 def _closefp(self): 227 def _closefp(self):
229 if self._fpdoclose and self._fp is not None: 228 if self._fpdoclose and self._fp is not None:
230 self._fp.close() 229 self._fp.close()