D3716: ui: add an unsafeoperation context manager that can block SIGINT

yuja (Yuya Nishihara) phabricator at mercurial-scm.org
Sun Jun 17 00:53:44 EDT 2018


yuja added a comment.


  >   I agree with @yuja that we should move this to `util.py` or one of its
  > 
  > siblings and rename it to `uninterruptable` or some such.
  
  procutil.py would be a better place.
  
  > That being said, signal handlers are process global. And we do need to
  >  maintain persistent state so things don't get out of whack if we have
  >  overlapping calls, potentially from multiple threads (e.g. in the case
  >  of hgweb). So maybe `ui.py` - or even a global variable in that module -
  >  is the proper place for such state.
  
  I think `ui`-level blocking flag is fine. We won't have to care about
  overlapped requests from threads because `signal.signal()` just doesn't
  work in sub threads.
  
  What I had in mind was something like the following:
  
    class ui:
        @contextmanager
        def uninterruptable(self):
            if already blocked or not enabled:
                yield
                return
            with procutil.uninterruptable(warn=self.warn, onlysigint=True,
                                          allowdoublesigint=True):
                set blocked
                yield
                clear blocked

REPOSITORY
  rHG Mercurial

REVISION DETAIL
  https://phab.mercurial-scm.org/D3716

To: durin42, #hg-reviewers, indygreg
Cc: indygreg, yuja, martinvonz, mercurial-devel


More information about the Mercurial-devel mailing list