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

Yuya Nishihara yuya at tcha.org
Sun Jun 17 00:51:48 EDT 2018


>   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
```


More information about the Mercurial-devel mailing list