331 try: |
332 try: |
332 yield |
333 yield |
333 finally: |
334 finally: |
334 self._blockedtimes[key + '_blocked'] += \ |
335 self._blockedtimes[key + '_blocked'] += \ |
335 (util.timer() - starttime) * 1000 |
336 (util.timer() - starttime) * 1000 |
|
337 |
|
338 @contextlib.contextmanager |
|
339 def uninterruptable(self): |
|
340 """Mark an operation as unsafe. |
|
341 |
|
342 Most operations on a repository are safe to interrupt, but a |
|
343 few are risky (for example repair.strip). This context manager |
|
344 lets you advise Mercurial that something risky is happening so |
|
345 that control-C etc can be blocked if desired. |
|
346 """ |
|
347 enabled = self.configbool('experimental', 'nointerrupt') |
|
348 if (enabled and |
|
349 self.configbool('experimental', 'nointerrupt-interactiveonly')): |
|
350 enabled = self.interactive() |
|
351 if self._uninterruptible or not enabled: |
|
352 # if nointerrupt support is turned off, the process isn't |
|
353 # interactive, or we're already in an uninterruptable |
|
354 # block, do nothing. |
|
355 yield |
|
356 return |
|
357 def warn(): |
|
358 self.warn(_("shutting down cleanly\n")) |
|
359 self.warn( |
|
360 _("press ^C again to terminate immediately (dangerous)\n")) |
|
361 return True |
|
362 with procutil.uninterruptable(warn): |
|
363 try: |
|
364 self._uninterruptible = True |
|
365 yield |
|
366 finally: |
|
367 self._uninterruptible = False |
336 |
368 |
337 def formatter(self, topic, opts): |
369 def formatter(self, topic, opts): |
338 return formatter.formatter(self, self, topic, opts) |
370 return formatter.formatter(self, self, topic, opts) |
339 |
371 |
340 def _trusted(self, fp, f): |
372 def _trusted(self, fp, f): |