import functools
import signal


def reset_signal_handlers(func):
    """
    Decorator that resets signal handlers from the decorated function. Useful
    for workers where we actively want handlers defined on the supervisor to be
    removed, because they wouldn't work on the worker process.
    """

    @functools.wraps(func)
    def wrapped(*args, **kwargs):
        signal.signal(signal.SIGTERM, signal.SIG_DFL)
        signal.signal(signal.SIGINT, signal.SIG_DFL)
        signal.signal(signal.SIGCHLD, signal.SIG_DFL)
        return func(*args, **kwargs)

    wrapped.__wrapped__ = func
    return wrapped