def METHOD_NAME(self):
    def handle_sigterm(*_):
        with handling_exceptions():
            raise TerminatedException('Terminated by signal')
    prev = signal.signal(signal.SIGTERM, handle_sigterm)
    try:
        yield
    finally:
        try:
            signal.signal(signal.SIGTERM, prev)
        except TypeError as e:
            #workaround for a strange issue on app cleanup. See https://bugs.python.org/issue23548
            if 'signal handler must be signal.SIG_IGN' not in str(e):
                raise