import signal


def set_timeout(timeout, func):
    """
    Call provided function and interrupt after given timeout.
    """
    def timeout_handler(*args):
        raise TimeoutError()

    try:
        signal.signal(signal.SIGALRM, timeout_handler)
        signal.alarm(timeout)
        return func()
    finally:
        signal.signal(signal.SIGALRM, lambda *args: None)
    return False